How to check CheckListBox item with single click?

C#WinformsCheckbox

C# 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#

Set the property at Design Time in this way

enter image description here

or by code:

CheckedListBox.CheckOnClick = true;

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);

}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPratik DeoghareView Question on Stackoverflow
Solution 1 - C#rahulView Answer on Stackoverflow
Solution 2 - C#daniele3004View Answer on Stackoverflow
Solution 3 - C#Scope CreepView Answer on Stackoverflow
Solution 4 - C#tjmaherView Answer on Stackoverflow
Solution 5 - C#AdiiiView Answer on Stackoverflow