What a pain in the ass this was. There are fifty thousand tutorials on the net talking about this and all of them give some variation of this:-
System.Collections.Arraylist list = new System.Collections.Arraylist();
_randomListbox.DataSource = list;
_randomListbox.DisplayValue = “SmackTalk”;
Where item is a simple data structure with a string value called “SmackTalk” which will be used as the display string. This is where they all end! Assuming that what, we’ve completely finished data processing and there will be no changes? No user input or interaction? Argh, I was tearing my hair out! What they never mention is this.
Unless an IList also implements IBinding (which the most common IList, ArrayList, and its strongly typed sibling List<> don’t.), then changes to the list will NOT reflect as changes in the listbox.
The answer to this is so stupid its almost funny, except for the sheer amount of time (easily upwards of an hour) I spent on this problem tonight. Not because there arn’t other ways to do this (hell, give me a foreach loop any day), but because I hate it when I know something should be working and isn’t.
The solution? Add this snippet underneath any changes you make to your IList and you want the listbox updated.
BindingManagerBase bmb = _randomListBox.BindingContext[list];
Apparently suspending and resuming the binding process (something you normally do to save processing power and prevent constant refreshing during long updates I guess) forces the list to recheck the IList manually. Thus, it updates for us.
Thank god for that at long last.