|
-
Oct 25th, 2017, 07:45 AM
#6
Re: Unwanted trigger of an event.
 Originally Posted by NeedSomeAnswers
If you add your handlers in code rather than in the designer (which is where they are added if you just double click on an event in the properties window, or double click on a control to create an event), then you can control exactly when they are bound.
This means you can do your call to Fill your ComboBox and set its SelectedIndex first, then add your handler. This way it won't trigger while you loading data on form load, but it will trigger the rest of the time.
Generally i now add all my handlers in a sub that i call at the end of Form_Load after i have loaded all data so i have full control as to what event are firing when.
 Originally Posted by kpmc
Agreed... half-way through the first post, my thought was "Oh, hey... so the problem is the code fires off before it needs to because of the way things are bound... simple fix... don't wire up the event handler until after the combo box is bound and the -1 index is set... then use AddHandler to set the SelectedIndexChange event handler."
I do this just about anytime I deal with bound data where controls also use their change event - or other events - to then act upon the data.It might seem like a hassle, but using AddHandler is really simple, so it's not that big of a deal.
-tg
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|