checked list box Data Source Does
I have bounded a CheckedListBox
To a DataSource
Which has been declared in class scope , but when I update DataSource
in some method , CheckedListBox
does not change , but when i r开发者_StackOverflow社区ecall 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";
}
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.
use refresh method.
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";
chListBox.Refresh();
}
精彩评论