Which CheckedListBox event triggers after a item is checked?

前端 未结 12 573
攒了一身酷
攒了一身酷 2020-11-28 13:24

I have a CheckedListBox where I want an event after an item is checked so that I can use CheckedItems with the new state.

Since ItemChecked is fired before

12条回答
  •  情书的邮戳
    2020-11-28 13:47

    In normal behaviour, when we check one item, the item's check state will change before the event handler is raised. But a CheckListBox has a different behaviour: The event handler is raised before the check state of the item changes and that makes it difficult to correct our jobs.

    In my opinion, to solve this problem, we should defer the event handler.

    private void _clb_ItemCheck(object sender, ItemCheckEventArgs e) {
     // Defer event handler execution
     Task.Factory.StartNew(() => {
         Thread.Sleep(1000);
         // Do your job at here
     })
     .ContinueWith(t => {
         // Then update GUI at here
     },TaskScheduler.FromCurrentSynchronizationContext());}
    

提交回复
热议问题