How can I stop it from going to SelectedIndexChanged?!

I load a datatable for the listbox but that causes the SelectedIndexChanged event which I do not want unless the user actually does this.

How can I make it stop or am I going about this the wrong way? The way it is now it will keep on reloading the datatable which is bad.

Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pnUserDetails.Visible = False
pnCrossingDetails.Visible = False

lbZones.DisplayMember = "zonename"
lbZones.ValueMember = "zoneid"
lbZones.DataSource = user.Zone.Select_Zones(USERID)

lbCrossings.DisplayMember = "combined"
lbCrossings.ValueMember = "crossing"
End Sub

Private Sub lbZones_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbZones.SelectedIndexChanged
lbCrossings.DataSource = user.Zone.crossing.Select_Crossings(CType(lbZones.SelectedValue, Integer))

End Sub

[977 byte] By [codefund.com] at [2007-12-16]
# 1
When the table is loaded, the SelectedIndex _does_ change (from -1 to 0), so the event will fire. In order to avoid this, add the event handler explicitly: remove the "Handles lbZones.SelectedIndexChanged" and add
AddHandler lbZones.SelectedIndexChanged, AddressOf lbZones_SelectedIndexChanged
to your load.
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
when the ListBox is bound to a list , then position changes in the list will cause the SelectedIndex event to fire.

One way around it would be to inherit from the ListBox and override the OnSelectedIndexChanged method to not fire the SelectedIndexChanged event at all.

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...