ComboBox DataSource - on the fly changes?

C

cj

I have a ComboBox that I populate using a DataSource (an ArrayList of
objects of the same type.)

When I add and remove items in the data source array list, I can't get the
list of items shown in the ComboBox to update automatically. I had trouble
getting the DataSource to take when I first created this ComboBox (a few
weeks ago), and the only way I found to get it to work is to set the Parent
property (and then I handled the ParentChanged event and set the DataSource,
DisplayMember, ValueMember, etc., there.

Do I have to set the Parent every time I make changes to the DataSource to
get the ComboBox to repopulate, or is there a better way?

Thanks,
cj
 
N

Nicholas Paldino [.NET/C# MVP]

cj,

Instead of binding to an ArrayList, create a shell for the ArrayList
which implements IBindingList and binds to that.

Or, in .NET 2.0, use the generic BindingList class and bind to that.

Hope this helps.
 
C

cj

Thanks! I'll try out the IBindingList.

Nicholas Paldino said:
cj,

Instead of binding to an ArrayList, create a shell for the ArrayList
which implements IBindingList and binds to that.

Or, in .NET 2.0, use the generic BindingList class and bind to that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

cj said:
I have a ComboBox that I populate using a DataSource (an ArrayList of
objects of the same type.)

When I add and remove items in the data source array list, I can't get
the list of items shown in the ComboBox to update automatically. I had
trouble getting the DataSource to take when I first created this ComboBox
(a few weeks ago), and the only way I found to get it to work is to set
the Parent property (and then I handled the ParentChanged event and set
the DataSource, DisplayMember, ValueMember, etc., there.

Do I have to set the Parent every time I make changes to the DataSource
to get the ComboBox to repopulate, or is there a better way?

Thanks,
cj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top