C# - 是否可以从 a 到 z 排列组合框项目? [英] C# - is it possible to arrange ComboBox Items from a to z?

查看:14
本文介绍了C# - 是否可以从 a 到 z 排列组合框项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个组合框中有一个非常凌乱的长项目,里面装满了字符串,将它从 a 到 z 排序以使其更容易跟踪会很可爱.可能吗?

解决方案

我能想到的方法有两种:

A) 使用 WinForms 组合框 Sorted 属性

如果您使用的是 WinForms,则可以使用

B) 使用 OrderBy

手动对您的列表进行排序

如果组合框中的数据来自列表形式,请使用 OrderByList 数据的ComboBox 在设置之前.

这是一个例子:

var myList = new List() {"q","w","e","r","t","y"};var sorted = a.OrderBy(c => c).ToArray()comboBox1.Items.AddRange(排序);

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 possible ways that I could think of:

A) Use the WinForms Combobox Sorted Property

If you're using WinForms, you can use ComboBox.Sorted = true;

B) Manually Sort your List with OrderBy

If the data in your combo box comes from in a form of a list, use OrderBy to the List of data you are going to put in the ComboBox before setting it.

Here's an example:

var myList = new List<string>() {"q","w","e","r","t","y"};
var sorted = a.OrderBy(c => c).ToArray()
comboBox1.Items.AddRange(sorted);

这篇关于C# - 是否可以从 a 到 z 排列组合框项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆