winforms - 排序组合框

标签 winforms sorting data-binding combobox

我正在使用带有组合的数据绑定(bind)来在下拉列表中显示我的对象。数据绑定(bind)后,组合框需要自动按字母顺序对其中的数据进行排序。如何才能做到这一点?我希望逻辑是通用的并直接应用于组合框,而不是应用于绑定(bind)到它的对象。

最佳答案

数据绑定(bind)组合框无法直接排序。您必须对基础数据源进行排序。这是来自 MSDN:

Attempting to set the Sorted property on a data-bound control raises an
ArgumentException. You must sort the data using the underlying data model.

因此您也许可以使用 SortedList 作为绑定(bind)源。

关于winforms - 排序组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11560943/

相关文章:

wpf - 使用 WPF、MVVM 和 Bindings 与 WinForm UserControl,如何成功集成?

c# - For循环中的日期时间

algorithm - 有没有办法使用 Foldr 或 Foldl 函数在 SML 中编写堆排序算法?

c# - TextBlock 选择性线条着色

c# - Control.OnPaint() 在自定义控件中被调用两次

c# - 以编程方式触发控件的事件

javascript - 为什么 JavaScript 不能对 [5, 10, 1] 进行排序?

mongodb - MongoDB 如何在一个集合中排序他们的文档?

wpf - 通过两个级别绑定(bind)到 TemplatedParent

c# - 使用手动数据绑定(bind)在 Formview 中检索键和新值