开发者

Select object from combobox title filled with hashtable of object in C#

开发者 https://www.devze.com 2023-03-16 01:10 出处:网络
开发者_JS百科I have a C# form application. I have a hashtable of object (id - title ...) . I fill the combobox with the id and the title. When someone select an item, i get the id and title, extract t

开发者_JS百科I have a C# form application. I have a hashtable of object (id - title ...) . I fill the combobox with the id and the title. When someone select an item, i get the id and title, extract the id and get the object from the hashtable.

I use List where I need some sorting.

Is there a better way to do that ?

Thanks


You can create derived class from 'KeyedCollection' http://msdn.microsoft.com/en-us/library/ms132438.aspx. Let's assume it will contain items of 'SomeItem' class. That class have properties Id, Name and some others. Set this KeyedCollection as ComboBox datasource. Then set ValueMemeber = "Id", DisplayMember = "Name"; After that you can cast "SelectedItem" to 'SomeItem' class and work with it.


You can use SortedDictionary

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号