tags:

views:

157

answers:

1

hi i have bounded a checked list box To a Data Source Which has been declared in class scope , but when i update data source in some method , checked list box does not change , but when i recall following codes again it changes :

    private void UpdateDataSource(string textToSearch )
    {

        dsContacts = dbSms.fillDataSet("Select * From Contacts Where ContactName Like'%" + textToSearch + "%'", "Contacts");

        chListBox.DataSource = dsContacts.Tables["Contacts"];
        chListBox.DisplayMember = "ContactName";
        chListBox.ValueMember = "ContactNumber";

    }
A: 

It's the DataSource setter that's triggering the update. When you set it to a new value it will refresh the check list box.

Darin Dimitrov
how to be aware of updating ? i have declared DataSource in class scope
persian Dev
Yes but until you call the DataSource `setter` your control will not update. It keeps a copy of the original data source.
Darin Dimitrov
would you please explain it more ...... thanks
persian Dev
Every time you need to refresh the check box list control you need to call your `UpdateDataSource` method.
Darin Dimitrov