Windows Develop Bookmark and Share   
 index > Windows Forms General > How can I stop it from going to SelectedIndexChanged????!
 

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

MigrationUser 1  Friday, March 21, 2003 2:41 PM
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.
MigrationUser 1  Friday, March 21, 2003 5:30 PM
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.
MigrationUser 1  Friday, March 21, 2003 6:24 PM

You can use google to search for other answers

Custom Search

More Threads

• How to perform arithematic on a control's width property?
• Imagelist, c# and MissingManifestResourceException
• browser & winform
• WebBrowser control and Stylesheet
• Text Box & Dates
• How Do I Draw on a Form whenever I want
• Rolling logs with log4net?
• Hue Saturation and Lightness editing of an Image
• Label + In-Place Editing
• how to get Office Accounting combo boxes?