i and having a combo box which contain a valueMember for each item in the combo box.....
i am also having a checklist box which also contain some item ...... what i want to do is to check and uncheck the checklistbox base on the selectedValue of the combobox....
here is my code
- int STAFF_IDs = (int)txtTeacher.SelectedValue;
- con.Open();
- SqlDataAdapter ds1 = new SqlDataAdapter("select * FROM SUBJECT_STAFF where STAFF_ID= '" + STAFF_IDs + "' ", con);
- DataTable dt1 = new DataTable();
- ds1.Fill(dt1);
- if (dt1 != null && dt1.Rows.Count > 0)
- {
- for (int i = 0; i < checkedListBox1.Items.Count; i++)
- {
- for (int k =0; i< dt1.Rows.Count; i++)
- {
- checkedListBox1.SetItemCheckState(i, (STAFF_ID == Convert.ToInt32(dt1.Rows[k]["STAFF_ID"]) ? CheckState.Checked : CheckState.Unchecked));
- } }//end for
- }//end if
(NOTE: the purpose of the code is to have a combo box that contain staff name...... and a checklistbox that contain the list of subject..... then i want to assign subjects to staffs from the checklistbox..... again whenever a staff is selected from the combobox, i want the subject that has been assigned to the particular staff be checked on the checklistbox)

Madhanmohan DevarajanRank #342 · 7.3K reputationPosted Mar 28, 2018, 8:26 AM EDT
Hi Gabriel,
In your case, you need to have one Combo Box (containing the list of staff) and one multi select list box (subjects).
Gabriel olayinka143 reputationPosted Mar 28, 2018, 10:04 AM EDT
Madhanmohan DevarajanRank #342 · 7.3K reputationPosted Mar 29, 2018, 7:06 AM EDT
Hi Gabriel,
Please have a look at the link that i have shared, those examples for Listbox, multiselect list box and pre-selected list box are for C# webforms only. And more over there would not be much difference between Checklistbox and Multiselect listbox.