c# - 对文本框对象列表进行排序

标签 c# list sorting textbox

我想扫描一些序列号以只读文本框。我创建了一个文本框列表,但我不知道如何按文本框名称对它们进行排序:

// 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/

相关文章:

php - 比较字符串 "numerically first"

c++ - 计数排序 : Why we need sum of previous counts?

python - 从最小值开始对嵌套字典中的值进行排序。至最大

c# - 在单个查询中更新表中的多个值

python - 在Python中用特定单词分割列表中的一些字符串项

c# - 回滚而不抛出异常?

python : count the number of different values for a given attribute in a list of objects

python - 访问/使用元组列表中的元素 python 3.x

c# - 如何使用 IComparable 和 IComparer 对对象列表进行排序

c# - 如何更改我的图表控件背景颜色