troubleshooting Question

Listbox Problem: Why does my ListBox reset the values on a TabControl SelectedIndex Change?

Avatar of Wease7
Wease7 asked on
Visual Basic.NET
5 Comments1 Solution487 ViewsLast Modified:
I've got a Form with a TabControl.  On the second tab, I have a ListBox with the selection mode set to MultiSimple.  When I load the form, the SelectedIndexChanged event of the Tab Control gets called before the Form Load does.  I have no idea why that is.  I load up my values from my DB in the Form Load event, but when I select the second tab, the values of that ListBox and what is supposed to be selected are lost.  It goes back to selecting the first value, which it does by default.  Again, I have no idea why.  So to fix that, I ended up loading up the values of that ListBox from the DB on that SelectedIndexChanged event of the Tab Control.  Which works fine (so everytime that specific tab is selected, it loads the correct values), but if someone changes the values and then goes to a different tab, once they go back to that tab, all of those values they just selected are gone.  Of course, since my SelectedIndexChanged event was tripped again and it reloaded the values from the DB.

Is this a bug in the .NET Framework?  Or am I doing something wrong?  None of the other controls act this way.  They all load up fine and don't change their values based on a Tab Control SelectedIndexChanged event.  What am I doing wrong?  Is there something I'm not setting somewhere?

If this truly is a bug, how can I get around this?  I want the values to load up properly and also keep them selected in that Listbox if the tabs change.  Any ideas?
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros