so, I have a checkListBox that i'm trying to get the value member of the checked boxes. Currently, I can get the selectedValue of one item. If multiple items are checked, i get the same selectedValue for each.
The box is populated like so...
SqlConnection cn = new SqlConnection(Properties.Settings.Default.cs);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("usp_getCustomers, cn);
DataSet ds = new DataSet();
da.Fill(ds, "usp_getCustomers");
chkListCustomer.DataSource = ds;
chkListCustomer.DisplayMember = "usp_getCustomers.name";
chkListCustomer.ValueMember = "usp_getCustomers.id";
chkListCustomer.SelectedIndex = -1;
On a button click, this is what i'm doing to TRY and get the selected values. It gives me the right ID for one item, but if multiple items are checked, it gives the same ID back for all.
foreach (int indexChecked in chkListCustomer.CheckedIndices)
{
MessageBox.Show("Index#: " + indexChecked.ToString() + ", is checked. Checked state is:" + chkListCustomer.SelectedValue.ToString() + ".");
}
example output is:
"Index#: 1, is checked. Checked state is:984"
"Index#: 2, is checked. Checked state is:984"
"Index#: 3, is checked. Checked state is:984"
thanks for the help!