Question Why raised events are called in wrong order?

LeoVBNET

Member
Joined
Apr 9, 2013
Messages
5
Programming Experience
5-10
Hi.
I noticed that there is some raised events that go through in reverse order. For example...
1) The event "CheckedListBox.ItemCheck" occurs before the item check changed. Fortunately I solve this problem with e.Newvalue and e.CurrentValue.

2) Working with MDI forms the event "MdiChildActivate" occurs before the MDI-child really open or close. In fact, when close() method is called the events raise as follow: 1) MdiChildActivate 2) MDI-child Closing 3) MDI-child Closed. It makes that the MDI-parent form does not know neither who MDI-child raised the event nor if it was opened or closed. So, if you ask for MDI-parent.MdiChildren.Length this value is not update.

Thanks.
 
1) That's just how it is. You might want to intercept an attempt to check an item and do something before actually giving visual feedback.

2) Same reason as above. You can cast Sender to the proper type to retrieve the form that raised the event. As for the rest, you should not handle the Activate event if what you want is actually the Closing or Closed or Load events. Handle the proper event and you shouldn't have a problem.
 
Back
Top