我有一个 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/