using datasource with CheckedListBox and all items selected
13,709
Following up on my comment earlier, I'm posting an answer: it can't be done without a loop.
This will select all the items:
CheckedListBox1.DataSource = DataSource1.Tables[0];
CheckedListBox1.DisplayMember = "Col_Name";
for (int i = 0; i < CheckedListBox1.Items.Count; i++)
{
CheckedListBox1.SetSelected(i, true);
}
This will check all the items:
CheckedListBox1.DataSource = DataSource1.Tables[0];
CheckedListBox1.DisplayMember = "Col_Name";
for (int i = 0; i < CheckedListBox1.Items.Count; i++)
{
CheckedListBox1.SetItemChecked(i, true);
}
Author by
Sérgio D.
Updated on June 18, 2022Comments
-
Sérgio D. almost 2 years
I using this code to create and add item for DataSource in my CheckedListBox.
CheckedListBox1.DataSource = DataSource1.Tables[0]; CheckedListBox1.DisplayMember = "Col_Name";
How do I create all item selected (without using loop)?