Adding new item in ComboBox with items in DataSource

Adding new item in ComboBox with items in DataSource

Post by marcob » Thu, 01 Feb 2007 02:00:29


I have a ComboBox and a List of objects to popolate items.
I use the DataSource property and not the List collection:

List<foo> lst = new List<foo>;
//add elements into the list
//...
comboBox1.DataSource = lst;

This work fine, items appear.
Now I have a button near the combo box and I want to add a new element
in the list when the user click the button.

If I try to add a new item in the comboBox1.List collection the
framework returns the error "Items collection cannot be modified when
the DataSource property is set.", so I try to add the new item in the
List linked to DataSource property:

lst.Add(new foo);

comboBox doesn't return any error, but the new item doesn't appear.

HOW CAN I FORCE COMBOBOX TO REFRESH THE ITEMS? OR ANY NEW IDEA TO
ADDING AN ITEM AFTER THE LIST IS POPOLATED?

Thanks!
Marco