我想扫描一些序列号以只读文本框。我创建了一个文本框列表,但我不知道如何按文本框名称对它们进行排序:
// This gets all the textboxnames ands makes an array of names and textboxes
foreach (Control groupbox in this.Controls)
{
if (groupbox is GroupBox)
{
foreach (Control textbox in groupbox.Controls)
{
if (textbox is TextBox)
{
theTextBoxesList.Add((TextBox)textbox);
TextBoxNames.Add(textbox.Name);
}
}
}
}
TextBoxNames.Sort();
theTextBoxesList.Sort?????
最佳答案
我认为要对 TextBox List 进行排序,LINQ Query 可能会对您有所帮助。使用 OrderBy 对 TextBox 按升序排序,或使用 OrderByDescending 对 TextBox 按降序排序。
升序排序:
theTextBoxesList = theTextBoxesList.OrderBy(x => x.Name).ToList();
降序排序:
theTextBoxesList = theTextBoxesList.OrderByDescending(x => x.Name).ToList();
这有帮助吗?
有关排序数据的更多信息,请访问 http://msdn.microsoft.com/en-us/library/bb546145.aspx
关于c# - 对文本框对象列表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12328087/