views:

313

answers:

2

i need to override the base CheckedListBox behaviour.

it is possible to check and uncheck a CheckedListBox without any code attached to it.

i need to disable this behaviour so that i can implement custom code.

any ideas?

thanks. .

for example:

if (ListenCheckedListBox.GetItemChecked(0)) { ListenCheckedListBox.SetItemChecked(0, false); }

if (!ListenCheckedListBox.GetItemChecked(0)) { ListenCheckedListBox.SetItemChecked(0, true); }

does not work because the controls default behaviour already does this anyway.

hopefully you can understand my issue now.

A: 

You can create your own CheckedListBox by inheriting from the built-in class and overriding the relevant methods.

As I understand your question, you don't want the items to be selected when the user clicks them, you want to control the selection entirely from your code.

To do this, you can override the OnItemCheck method, and control the new value that is being set:

public class CheckedListBoxEx : CheckedListBox
{
    protected override void OnItemCheck(ItemCheckEventArgs ice)
    {
        ice.NewValue = ice.CurrentValue;
    }
}

This can also be done by simply handling the ItemCheck event.

driis
that sounds interesting. im a beginner so my query is how do i do what you mentioned? how do i find the method i have to override to get it working the way i want it to work?
iEisenhower
no thats not quiet what i need. i want to be able to click and set its value also.i need to override the functions in the base class that toggles the checked value (depending on mouse clicks) without any coding.because of this the code is running twice. once when i update its state in code and secondly the default behaviour of the control also toggles it.
iEisenhower
A: 

ok i figured it out. i was seeing it wrong. i just handle for the checked state instead of defining it twice. once by the control second by me.

yes i was being silly!

iEisenhower