Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CheckedListBox Control - Only checking the checkbox when the actual checkbox is clicked

I'm using a CheckedListBox control in a small application I'm working on. It's a nice control, but one thing bothers me; I can't set a property so that it only checks the item when I actually check the checkbox. What's the best way to overcome this? I've been thinking about getting the position of the mouseclick, relative from the left side of the checkbox. Which works partly, but if I would click on an empty space, close enough to the left the current selected item would still be checked. Any ideas regarding this?

like image 507
Oxymoron Avatar asked Jan 19 '10 14:01

Oxymoron


2 Answers

I succesfully used this property:

CheckedBoxList.CheckOnClick

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.checkedlistbox.checkonclick?view=netframework-4.7.2

like image 61
Francesco Avatar answered Sep 20 '22 09:09

Francesco


I know this thread's a bit old, but I don't think it's a problem to offer another solution:

private void checkedListBox1_MouseClick(object sender, MouseEventArgs e)
{
    if ((e.Button == MouseButtons.Left) & (e.X > 13))
    {
        this.checkedListBox1.SetItemChecked(this.checkedListBox1.SelectedIndex, !this.checkedListBox1.GetItemChecked(this.checkedListBox1.SelectedIndex));
    }
}

(With the value of CheckOnClick = True).

You could use that thingy with the rectangle, but why make it more complex the it needs to.

like image 37
Wilfred Avatar answered Sep 19 '22 09:09

Wilfred