C# Dictionary as a ListBox.DataSource
- by Steve H.
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.