在没有的CheckedListBox事件ItemChecked? [英] No ItemChecked event in a CheckedListBox?

查看:121
本文介绍了在没有的CheckedListBox事件ItemChecked?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ListView控件有一个 ItemCheck 事件,这是之前的项目变化解雇的以及 ItemChecked 事件被解雇后的 的项目的变化。见<一href=\"http://stackoverflow.com/questions/912798/listview-itemcheck-versus-listview-itemchecked-in-net\">this SO质疑了解详细信息。

The ListView control has an ItemCheck event which is fired before the item changes, and an ItemChecked event that is fired after the item changes. See this SO question for more detail.

CheckedListBox控件只具有ItemCheck事件。

The CheckedListBox control only has the ItemCheck event.

什么是做这样的事情用的CheckedListBox的最佳方式?

What is the best way to do something like this with a CheckedListBox?

private void checkedListBox_ItemChecked(object sender ItemCheckedEventArgs e)
{
    okButton.Enabled = (checkedListBox.CheckedItems.Count > 0);
}

补充问题:
为什么没有CheckedListBox.ItemChecked事件?

Supplemental question: Why is there no CheckedListBox.ItemChecked event?

推荐答案

一个好的技巧来处理,不能处理时,他们提出的是拖延处理事件。您可以使用Control.BeginInvoke()方法做什么,只要所有的事件的调度运行,副作用齐全,UI线程再次进入空闲状态。为树视图通常也非常有帮助,另外一个胡思乱想的控制。

A nice trick to deal with events that you cannot process when they are raised is to delay the processing. Which you can do with the Control.BeginInvoke() method, it runs as soon as all events are dispatched, side-effects are complete and the UI thread goes idle again. Often helpful for TreeView as well, another cranky control.

    private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) {
        this.BeginInvoke((MethodInvoker)delegate { 
            okButton.Enabled = checkedListBox1.CheckedItems.Count > 0;
        });
    }

只是以防万一:这有没有关系线程和诀窍是相当便宜。

Just in case: this has nothing to do with threading and the trick is quite cheap.

为什么没有ItemChecked事件?真的不知道。的CheckedListBox只是没有很好的控制。绝对不是在原来的WinForms团队的大师之一完成的。

Why no ItemChecked event? Not really sure. CheckedListBox just isn't a very good control. Definitely not done by one of the gurus in the original Winforms team.

这篇关于在没有的CheckedListBox事件ItemChecked?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆