Combobox data binding fires selectedIndexchange event 4 times

  • Thread starter Thread starter Saima
  • Start date Start date
S

Saima

Hi,

does any one has any indea y binding a combobox with a
dataset fires its selected index change event 4 times? if
yes then how can i avoid it?
regards,Saima.

I am using the following code:

da.SelectCommand = cmd
da.Fill(ds, "VEHICLE_BRAND_TYPE")
Me.VehicleMakeTypecb.DataBindings.Clear()
Me.VehicleMakeTypecb.DataSource = ds.Tables
("VEHICLE_BRAND_TYPE")
Me.VehicleMakeTypecb.DisplayMember = "NAME"
 
Saima said:
does any one has any indea y binding a combobox with a
dataset fires its selected index change event 4 times?

because that's the way it's always been done, and if it's good enough for
the alpha testers then it's good enough for you
if yes then how can i avoid it?

set a flag before the binding and clear it after
then in the selectedindexchanged event check the flag and if you are binding
then exit sub
 
khorad,
thanks khorad.I already had found this work around , i was just looking
for the reason as to y this happens because i can't c the need of it.
anyways thanks for replying :)
saima.
 
There is another way, just tie the event after filling the combo:

For example:

' Filling the combo
da.SelectCommand = cmd
da.Fill(ds, "VEHICLE_BRAND_TYPE")
Me.VehicleMakeTypecb.DataBindings.Clear()
Me.VehicleMakeTypecb.DataSource = ds.Tables
("VEHICLE_BRAND_TYPE")
Me.VehicleMakeTypecb.DisplayMember = "NAME"

' From now I want the event to get called
AddHandler VehicleMakeTypecb.SelectedIndexChanged, AddressOf
VehicleMakeTypecb_SelectedIndexChanged
.....


' The following function will only be called when the selected index change
and not while creating the combo
Public Sub VehicleMakeTypecb_SelectedIndexChanged(ByVal sender as Object,
ByVal e as System.EventArgs)
' Do something
End sub


Hope this helps
Roberto
 
Back
Top