我有一个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中
发布于 2013-04-05 01:52:01
您可以通过订阅Format事件来格式化添加的每一项。
comboBox1.Format += (s, e) =>
{
e.Value = e.Value.ToString().ToUpperInvariant();
};但请注意,执行此操作时,第一项将被选中,因此除非在附加Format事件处理程序之前附加SelectedValueChanged事件处理程序,否则将触发SelectedValueChanged事件。
https://stackoverflow.com/questions/15817507
复制相似问题