Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Private Sub lstIndOccs_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lstIndOccs.SelectedIndexChanged

the method is fire when the form is loading instead of selected index changed how
can i delay it or solve this issue...
Posted
Updated 10-Jan-12 3:24am
v2
Comments
Simon_Whale 10-Jan-12 10:45am    
do you have something that alters the lstInd0ccs? at the load event? if so this will cause the selectedindexchanged event to be fired

Don't delay anything. Add a Boolean flag as a member of your declaring class (Form, Window, whatever). The flag will be false at first. In your event handler, take the value of this flag into account. If you want to do nothing, exit the method immediately if the flag is not set. When you are ready to do full processing, set the flag to true. You can do it at the end of the form constructor or later, in response to the event Form.Shown.

On note though. This behavior is done on purpose: the event is fired every time the selection is changed, no matter if the form is fully "loaded" or not. Instead of fighting this behavior, you should better use it. In other words, you should handle this even in the same way at all times. I would rather advise you review your code design to accommodate this.

—SA
 
Share this answer
 
Comments
thatraja 10-Jan-12 14:42pm    
Nice simple analysis, 5!
BTW Congrats to you too SA(MVP winner 2012)
Sergey Alexandrovich Kryukov 10-Jan-12 14:47pm    
Thank you very much, Raja. And -- my congratulations with another MVP you got; it is well deserved.
--SA
I agree with Simon.
do you have something that alters the lstInd0ccs? at the load event? if so this will cause the selectedindexchanged event to be fired
Probably you need to do changes in form_load event. I guess you set value something like lstIndOccs.SelectedIndex = 0. Always include the related code in your question.

BTW check this blog post for other help & give me feedback .NET Code Conversion[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900