Link to home
Start Free TrialLog in
Avatar of GivenRandy
GivenRandy

asked on

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?
Avatar of DotNetLover_Baan
DotNetLover_Baan

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

-Baan
Avatar of GivenRandy

ASKER

Nope.
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Ah, missed bottom part. This works:

         Dim dr As DataRow
         For Each dr In dt.Rows
            lstMyList.Items.Add(dr("MyColumn"))
         Next
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.

Roger