.net - .NET Winforms 组合框的显示格式为大写

标签 .net winforms combobox formatting

我有一个 Process 类型的对象数组 我想在组合框中显示此列表,按字母顺序排列且全部大写。

Process 对象属性“ProcessName”是“DisplayMember”;它是一个只读属性。

        private void Form1_Load(object sender, EventArgs e)
    {
        //get the running processes
        Process[] procs = Process.GetProcesses();
        //alphabetize the list.
        var orderedprocs = from p in procs orderby p.ProcessName select p;
        //set the datasource to the alphabetized list
        comboBox1.DataSource = orderedprocs.ToArray<Process>();
        comboBox1.DisplayMember = "ProcessName";

        // Make the display member render as UPPER CASE???
        //comboBox1.FormatString


    }

我怀疑答案就在FormatString

最佳答案

您可以通过订阅 Format 事件在添加每个项目时对其进行格式化。

comboBox1.Format += (s, e) =>
    { 
         e.Value = e.Value.ToString().ToUpperInvariant();
    };

但请注意,当您执行此操作时,将选择第一个项目,因此您的 SelectedValueChanged 事件将触发,除非您在附加 SelectedValueChanged 之前附加 Format 事件处理程序 事件处理程序。

关于.net - .NET Winforms 组合框的显示格式为大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15817507/

相关文章:

c# - 将引用存储在另一个变量中

.net - 如何在 VB.NET 中每 2 个数字向数字字符串添加空格?

.NET 属性 : Why does GetCustomAttributes() make a new attribute instance every time?

c# - 如何在 c# winforms 中显示小写字母的 KeyCode 和 KeyData

Extjs 组合框自动完成功能不起作用

c# - 使用 MVVM 将 WPF 绑定(bind)到 Popup 控件中的 ComboBox

c# - .net 中的单元和集成测试组织

c# - 带有 AutoSize 的面板内的 FlowLayoutPanel 问题

c# - 创建空白 XML 文件,然后附加到它

c# - WPF 组合框所选项目错误 - 显示 "System.Data.Entity.DynamicProxies"