Friday, August 25, 2006

ListBox SurprizEEE !!

.net Listbox is quirky . I was trying to set an ArrayList as the datasource of my list box .

my code looked like :

_list = new ArrayList();
myListBox.DataSource = _list;


I thought that once i Add or Remove entries to this list . It would reflect that automatically reflect and update it on the listbox view . But to my surprize that doesnt work so .

The way to get this working is :

everytime you change list u need to reset the Datasource , speaking in terms of code that means , u need to write somethin like

myListBox.DataSource = new ArrayList();
myListbox.DataSource = list;

you have to do this everytime you change the list.