开发者

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?

开发者_如何学JAVAthanks. .

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜