Blog Reader RSS LoveCherry 技术无极限 GEO MVP MS Project开源技术

Binding the Enum to the Dropdown Listbox and Sorting it on Values.

链接:http://www.codeproject.com/KB/combobox/DataBinding_with_Enum.aspx
KEY:
Since SortedList is capable to sort out the item by its "keys" What I did here is for "keys" I have used the Values of Enum and for Values I have used the Text of Enum. Previously It was otherway round I have filled the SortedList with Text of Enum as Keys and Values of Enum as Values of Sorted List. In this case SortedList will return the List with sorted by its Keys. But Since I want "Select" option to be at top with -1 value, What I did is instead of defining SortedList(Of String, Integer) I have defiend SortedList(Of Integer, String) and filled all the Values of Enum as Keys of the SortedList and Text as Values of the SortedList.
下拉框绑定数据源为sortedlist集合,该集合在更改数据时(插入,删除等)能够自动调整集合各元素顺序,根据value项,继承了Icomparable接口,因此我们无需手工改变其顺序。十分方便快捷。

posted @ 2008-05-13 11:18  大宋提刑官  阅读(235)  评论(0编辑  收藏  举报