简体   繁体   中英

C# Override CheckedListBox

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.

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM