ListBox - SelectionMode - MultiSimple - De-selecting All Will Select First

I have a ListBox that has the SelectionMode set to MultiSimple. If I select a couple things from the middle of the list and then de-select them all, after the last one is de-selected, it automatically selects the first one. It doesn't happen this way when I build it from scratch, so there must be some setting or code somewhere. I did a search and breakpoints all over the place, but cannot seem to find the culprit. Any ideas?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you executing any code in the click event, or selectionChanged event for the list?

GivenRandyAuthor Commented:
Sounds like it's VB.NET 2003 and that the ListBox is bound to a datasource.  So far as I can determine, the binding manager abhors a vacuum and, if nothing else is selected, will itself select the first item in the listbox.  I'm not saying there isn't a way round it, but I haven't found it while keeping the binding.

As you are using multiselect, are you actually making use of the binding other than to fill the list?  If not, you might consider filling it programatically fromt he datasource and dispensing with the binding.  That seems to overcome the problem.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

There's a reported bug regarding databound combobox:;en-us;327244 which also applies to listbox as far as I can tell. Now I simply avoid setting datasource for combobox/listbox, add items one by one instead as suggested in this KB file. If I do need both value and display member, I create a ListItem class with .value and .text property and add ListItem as the item in the combobox/listbox.
GivenRandyAuthor Commented:
We never use bound controls, so it was a surprise that this legacy code had it. Great insight!

Okay, I'm a VB.NET neophyte, so what is the spoon-fed code to convert? I have something like:

      Dim dt As DataTable
      dt = MyFunctionThatReturnsDataTable
      If dt.Rows.Count > 0 Then
         lstMyList.DataSource = dt

I'll award additional points for that. Ccan I still add separate entries like "Points for ...."? If not, I'll start a new question.
GivenRandyAuthor Commented:
Ah, missed bottom part. This works:

         Dim dr As DataRow
         For Each dr In dt.Rows
No need for a new question anyway, as your own answer looks fine.  But

Ccan I still add separate entries like "Points for ...."?

No, I don't think so.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.