Click here to Skip to main content
15,569,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Link a checkedListBox to DataTable(in c#)


Hi
hello

How can I Link a checkedListBox to DataTable?
For example for Link a ComboBox to DataTable, the following codes are exist:

C#
SqlConnection_11 = new SqlConnection(strcon_11);
SqlDataAdapter_11 = new SqlDataAdapter(SQL_String, SqlConnection_11);
DataSet DataSet11 = new DataSet();
SqlDataAdapter_11.Fill(DataSet11, "my_table");
BindingSource bs1 = new BindingSource(DataSet11, "my_ table ");
ComboBox.DataSource = bs1;
ComboBox.DisplayMember = "Col1";
ComboBox.ValueMember = "Col2";



But for checkedListBox, it dont possible. Because we cant write this line:
C#
checkedListBox.DataSource = bs1;



How can I do this?



Thanks very much
Posted
Updated 19-Oct-13 22:18pm
v2

1 solution

You can either add items like below

Quote:
foreach (DataRow item in dt.Rows)
{
MyCheckedListBox.Items.Add(item["Name"].ToString(), Convert.ToBoolean(item["Checked"]));
}


Or try something like below

Quote:
((ListBox)MyCheckBoxList).DataSource = dt;
((ListBox)MyCheckBoxList).DisplayMember = "name";
((ListBox)MyCheckBoxList).ValueMember = "enabled";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900