How to check CheckListBox item with single click?
C#WinformsCheckboxC# Problem Overview
I am coding Windows Forms
application in C# and using CheckListBox
Control.
How to check CheckListBox item with just single click?
C# Solutions
Solution 1 - C#
I think you are looking for
CheckOnClick property
set it to true
> Gets or sets a value indicating > whether the check box should be > toggled when an item is selected.
Solution 2 - C#
Solution 3 - C#
I just finished working through an issue where I had set CheckOnClick to True via the designer, but the UI was still requiring a second click to check items. What I found is that for whatever reason, the designer file was not updating when I changed the value. To resolve, I went into the designer file and added a line
this.Product_Group_CheckedListBox.CheckOnClick = true;
After this, it worked as expected. Not sure why the designer didn't update, but maybe this workaround will help someone.
Solution 4 - C#
You can also use a check box exterior to the CheckListBox to check/uncheck all items. On the same form add a checkbox near the CheckedListBox and name it CkCheckAll. Add the Click event for the CheckBox (which I prefer to the CheckChanged event). There is also a button (BtnAdd) next to the CheckedListBox which will add all checked items to a database table. It is only enabled when at least one item in the CheckedListBox is checked.
private void CkCheckAll_Click(object sender, EventArgs e)
{
CkCheckAll.Text = (CkCheckAll.Checked ? "Uncheck All" : "Check All");
int num = Cklst_List.Items.Count;
if (num > 0)
{
for (int i = 0; i < num; i++)
{
Cklst_List.SetItemChecked(i, CkCheckAll.Checked);
}
}
BtnAdd_Delete.Enabled = (Cklst_List.CheckedItems.Count > 0) ? true : false;
}
Solution 5 - C#
you can also check all by button click or click on checklist
private void checkedListBox1_Click(object sender, EventArgs e)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
checkedListBox1.SetItemChecked(i, true);
}