SelectedIndex_Changed event firing during load ?

  • Thread starter Thread starter Giri
  • Start date Start date
G

Giri

It would appear that the SelectedIndex_Changed event on a combobox is firing
during the load of a windows form..

Is this the case?

Is there any way to easily stop this from happening?

Thanks
 
Based on my research and experience, if you don't set the value for the
SelectedIndex property of the ComboBox on form-loading, there should be no
such event. Therefore, you can set the text for a ComboBox with the Text
property, rather set the the value for the SelectedIndex property.

Best regards,

Duke Sun
Microsoft Online Partner Support
<MCSE/MCDBA/MCSD>

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
It would appear that the SelectedIndex_Changed event on a combobox is firing
during the load of a windows form..

Is this the case?

Is there any way to easily stop this from happening?

Don't forget that you can turn remove the delegate that subscribes to the SelectedIndex_Changed event. This is especially useful with lists when you are populating them - a common action in the form load event.
In C# it is something like (uncompiled code)
this.comboBox1.SelectedIndexChanged -= new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//...do your initialization
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);

Ian Cooper
wwww.dnug.org.uk
 
Thanks for the replies !

I tried removing the delegate but it made no difference.. (There is no real
initialization code in the form_load)..

I need to upgrade the project to 1.1 so maybe that suggestion will fix the
issue.

Thanks
 
I can't reproduce the problem on 1.1.

Best regards,

Duke Sun
Microsoft Online Partner Support
<MCSE/MCDBA/MCSD>

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
Giri said:
It would appear that the SelectedIndex_Changed event on a combobox is firing
during the load of a windows form..

Is this the case?

Is there any way to easily stop this from happening?

Do you use a DataSource with the ComboBox?
The BindingContextChange event is fired everytime the ComboBox becomes
visible. (dont ask my why.)
BindingContextChanged fires the SelectedIndexChange Event.

ciao
Torsten
 
Back
Top