简体   繁体   English

C#排序列表框,添加到排序列表

[英]C# sort Listbox, add to a sorted list

I want to sort the elements in C# listbox by some field in the object element. 我想按对象元素中的某些字段对C#列表框中的元素进行排序。

Is there a method in C# that perform this task? C#中是否有执行此任务的方法? Maybe a function that receives a comparison function as a parameter or something like that? 也许是一个接收比较函数作为参数的函数或类似的东西?

another thing, when the listbox is sorted I want to add an element to a sorted list. 另一件事,当对列表框进行排序时,我想将元素添加到排序列表中。 is there such a method? 有这种方法吗?

thanks 谢谢

I would suggest using classical winforms binding to a System.Collections.SortedList.List<TKey,TValue> . 我建议使用经典winforms绑定到System.Collections.SortedList.List<TKey,TValue> All of the sorting will be done for you by the list, and most of the data transactions to and from the ListBox control will be done for you by the binding framework. 列表将为您完成所有排序,而绑定框架将为您完成往返于ListBox控件的大多数数据事务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM