C# - 是否可以从a到z排列ComboBox项目? [英] C# - is it possible to arrange ComboBox Items from a to z?
本文介绍了C# - 是否可以从a到z排列ComboBox项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常混乱的长项目充满字符串在组合框中,它将是可爱的只是排序从一个到Z,使它更容易跟踪。是可能吗?
I have a very messy long items full of strings in a combobox, and it would be lovely to just sort it from a to z to make it easier to track. Is it possible?
推荐答案
我可以想到两种简单的方法:
There are two easy ways that I could think of:
-
如果您使用Win Forms,只需使用
ComboBox.Sorted = true;
如果组合框中的数据来自列表形式,只需使用 OrderBy 到 ComboBox
之前的列表
strong>。
If the data in your combo box comes from in a form of a list, just use OrderBy to the List
of data you are going to put in the ComboBox
before putting it.
例如:
List<string> a = new List<string>()
{
"q",
"w",
"e",
"r",
"t",
"y",
"u",
"i",
"o",
"p",
"a",
"s",
"d",
"f",
"g",
"h",
"j",
"k",
"l",
"z",
"x",
"c",
"v",
"b",
"n",
"m",
};
comboBox1.Items.AddRange(a.OrderBy(c => c).ToArray());
这篇关于C# - 是否可以从a到z排列ComboBox项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文