首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.NET Winforms组合框的显示格式为大写

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

Stack Overflow用户
提问于 2013-04-05 01:11:39
回答 1查看 1.9K关注 0票数 2

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

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

代码语言:javascript
复制
        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中

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-05 01:52:01

您可以通过订阅Format事件来格式化添加的每一项。

代码语言:javascript
复制
comboBox1.Format += (s, e) =>
    { 
         e.Value = e.Value.ToString().ToUpperInvariant();
    };

但请注意,执行此操作时,第一项将被选中,因此除非在附加Format事件处理程序之前附加SelectedValueChanged事件处理程序,否则将触发SelectedValueChanged事件。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15817507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档