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接口,因此我们无需手工改变其顺序。十分方便快捷。

转载于:https://www.cnblogs.com/onlyendure/archive/2008/05/13/1194864.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值