Quote:
But for checkedListBox, it dont possible. Because we cant write this line:
checkedListBox.DataSource = bs1;
How can I do this?
The
DataSource[
^],
DisplayMember[
^],
ValueMember[
^] properties exist on the CheckedListBox control, but they are marked with the BrowsableAttribute(false). Therefore they are hidden from VS's intellisense, but you can still enter these properties.
I think that they were hidden due to
this old bug[
^], but I can not recreate the bug described in the article.
This works:
DataTable dt = new DataTable("mytable");
dt.Columns.Add("listitem", typeof(string));
dt.Columns.Add("something", typeof(Int32));
dt.Rows.Add(new object[] {"1", 2});
dt.Rows.Add(new object[] {"2", 23});
DataSet ds = new DataSet();
ds.Tables.Add(dt);
BindingSource bs = new BindingSource();
bs.DataSource = ds;
bs.DataMember = "mytable";
checkedListBox1.DataSource = bs;
checkedListBox1.DisplayMember = "listitem";