tags:

views:

282

answers:

1

Following is the code to populate combobox using DataSource

Dim CountryList As Array = MyCtrl.GetAllCountries
    With cbCountyList
      .DataSource = CountryList 
      .DisplayMember = "CountryName"
      .ValueMember = "CountryID"
    End With

After adding a new COuntry Name to Database I want to reflect the changes in combobox. Repeating this code is not an option becasue it triggers SelectIndexChange event and had to do some crappy work around to avoid that.

So I was wondering if there is way to refresh the combobox list. I actually thought binding with the DataSource property supposed to do it automatically. I also tried

cbCountyList.Refresh()

Thanks in advance.

+1  A: 

You should make a BindingSource sit inbetween the ComboBox and your DataSource. Then call BindingSource.ResetBindings(false). It will do all the magic for you.

Here is what I mean (in C#, but same idea):

BindingSource b = new BindingSource();
b.DataSource = CountryList;
cbCountryList.DataSource = b;
...
...
b.ResetBindings(false); // cbCountryList now has the latest countries
Matt Greer
Great thank you
fireBand