ComboBox.SelectedValueChanged event

  • Thread starter Thread starter Dominic Paquette
  • Start date Start date
D

Dominic Paquette

Hi,
I have a comboBox on a form. In the FormLoad event handler, I set the
DataSource, DisplayMember, and ValueMember properties. I noticed that when I
set the properties it causes something like 6 SelectedValueChanged events to
be fired. In the SelectedValueChangedEvent handler SelectedValue.ToString()
is equal to System.Data.DataViewManagerListItemTypeDescriptor
Anyone knows what this is, and if so if there is a way for them not to get
fired.
My problem is that I want to query the database whenever the user changes
the selection in the combobox and I can't do a query like this:
select * from employees where employeeID =
'System.Data.DataViewManagerListItemTypeDescriptor'

Well if anyone ran into this problem before please let me know
thanks in advance
dominic
 
This is a well known problem / feature of the ComboBox. It's especially
annoying when databinding is used.

You'll need to disconnect the event handler while the data is being loaded
and then wire it up afterwards.

If you're using C# just dont add the event handler at design time, wire it
up in the Form.Load event. If you're using VB you'll have to manually remove
the "handles blah blah" from the end of the service method and use
AddHandler / RemoveHandler to add or remove the event as you need it.

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
 
I ran into this issue also. The work around was to set a Boolean to true in
the load and then false when the load was complete. I check the Boolean
before the execution of my query and exit if it's true.
 
Back
Top