You can actually set the check state while you're adding the item(s), in
code.
this.checkedListBox1.BeginUpdate();
for (int x = 0; x < 25; x++)
{
this.checkedListBox1.Items.Add(x.ToString(), CheckState.Checked);
}
this.checkedListBox1.EndUpdate();
If you really need to set all the check states after you have added the
items, then you can use the SetItemChecked method.
this.checkedListBox1.BeginUpdate();
for (int x = 0; x < 25; x++)
{
this.checkedListBox1.Items.Add(x.ToString());
}
for (int x = 0; x < this.checkedListBox1.Items.Count; x++)
{
this.checkedListBox1.SetItemChecked(x, true);
}
this.checkedListBox1.EndUpdate();
I'm was just loading the CheckedListBox with some data. So you can either
set the check state when you're adding the items to the Items collection or
loop through and set them afterwards. There should be nothing wrong with
"checkedListBox1.Items.Count" (of course, insert the name of your control).
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.