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 CheckedItems is updated it won't work out of the box.
What kind of method or event can I use to be notified when the CheckedItems is updated?
Don't know if this applies but I wanted to use a checklistbox to filter results. So as the user checked and unchecked items I wanted the list to show\hide items.
I was having some issues which led me to this post. Just wanted to share how I did it without anything special.
Note: I have CheckOnClick = true but it would probably still work without
The event I use is "SelectedIndexChanged"
the enumeration I use is ".CheckedItems"
This give the results I think we may expect. So simplified it comes down to ....
Assuming you want to preserve the arguments from
ItemCheck
but get notified after the model was changed it should look like that:Where
CheckedItemsChanged
could be:I tried this and it worked:
Although not ideal, you can calculate the CheckedItems using the arguments that are passed through to the
ItemCheck
event. If you look at this example on MSDN, you can work out whether the newly changed item has been checked or unchecked, which leaves you in a suitable position to work with the items.You could even create a new event that fires after an item is checked, which would give you exactly what you wanted if you wished.
This works, not sure how elegant it is though!