C# Dictionary as a ListBox.DataSource
Posted
by Steve H.
on Stack Overflow
See other posts from Stack Overflow
or by Steve H.
Published on 2010-03-30T18:34:28Z
Indexed on
2010/03/30
18:43 UTC
Read the original article
Hit count: 976
I am trying to bind a dictionary as a DataSource to a ListBox. The solution in How to bind a dicationary to a ListBox in winforms will not work for me because my dictionary is a class-level variable and not a method-level variable, so I can not use var. When you put a class-level variable into new BindingSource(...) with null as the second argument I get an ArgumentNull exception.
How do I bind a class-level dictionary as a data source for a list box?
I don't like the List< KeyValuePair< string, string > > work-around becuase Where(...) and First(...) are ugly, complicated, and confusing compared to TryGetValue(...) and other Dictionary functionality.
© Stack Overflow or respective owner