Hi there, I have populate a CheckedListBox binding a DataSource with Display Member and Vlaue Member. I have saved the values of the checkedValues in Database with a Relational Table. I need to repopulate the checkedListbox getting the checked which value was checked(Saved) previously.I have done the First step. But in the Second step i am unable to get the index of the items to keep them checked comparing the relational table.
Following my code to bind the CheckedListBox:
private void FillCheckedListBox (CheckedListBox chkListBox, string sSql, string displayMember, string valueMember)
{
try {
SqlConnection con = new SqlConnection(DaoCodeGCommon.GetConstring());
con.Open();
DataTable accTable = new DataTable();
SqlCommand cmd = new SqlCommand(sSql, con);
SqlDataAdapter adpObj = new SqlDataAdapter(cmd);
accTable.TableName = "tbl";
adpObj.Fill(accTable);
con.Close();
chkListBox.DataSource = accTable;
chkListBox.ValueMember = valueMember;
chkListBox.DisplayMember = displayMember;
}
catch (Exception ex) {
throw ex;
}
}
Is there any way to repopulate the checkedListBox?