I created an ArrayList that contains KeyValuePair <string, string> objects. There are ListBoxes that I would like to bind to this list, so I donβt need to populate them by iterating while copying all the data that I have in the above ArrayList.
I am a Delphi programmer, and in Delphi I would use a ListView control, set its OwnerData property to true, and then use the OnData event to make this element (with the specified index) display any part of the data from the array element with the same index. The OnData method gives me the currently displayed item as a parameter, so I can access, for example, its Index, Caption, and SubItems properties. Based on this index, I can get an element to display some data from an array element that has the same index. If this array is changed, just update the ListView and / or set its Count property if the length of the array has changed.
How to achieve the same goal in C # using a ListBox control? I set the listBox.DataSource property to myArrayList containing KeyValuePairs. Now I would like the listBox to display the keys of the KeyValuePairs objects.
source
share