What is the proper way to load a ListBox in C# .NET 2.0 Winforms?
I thought I could just bind it to a DataTable. No such luck.
I thought I could bind it with a Dictionary. No luck.
Do I have to write an class called KeyValuePair, and then use List<KeyValuePair> just to be able to load this thing with objects? Maybe I am missing something obvious. I want my display text and values to be different values.
Simple code example. Say you have a
Personclass with 3 properties.FirstName,LastNameandAge. Say you want to bind your listbox to a collection ofPersonobjects. You want the display to show the first name, but the value to be the age. Here’s how you would do it:The trick is the
DisplayMember, and theValueMember.