Strange bug in listbox with Multiselect = 2 and Sorted = True

Set a ordinary listbox with Sorted=True and Multiselect=2

Private Sub Form_Load()
List1.AddItem "ann"
List1.AddItem "beth"
List1.Selected(0) = True
End Sub

Start the program, then type in "b". The second item will be higlighted and selected, as it should, leaving the first one unselected. But - one or two seconds later, the first item is selected again!!!

Further testing shows that the "ann" item now has the Selected property set to False - even if it (incorrectly) shows up as "selected" - along with the "beth" item (which now has been selected by typing "b")...

Any way around this?

Comments

  • : Set a ordinary listbox with Sorted=True and Multiselect=2
    :
    : Private Sub Form_Load()
    : List1.AddItem "ann"
    : List1.AddItem "beth"
    : List1.Selected(0) = True
    : End Sub
    :
    : Start the program, then type in "b". The second item will be higlighted and selected, as it should, leaving the first one unselected. But - one or two seconds later, the first item is selected again!!!
    :
    : Further testing shows that the "ann" item now has the Selected property set to False - even if it (incorrectly) shows up as "selected" - along with the "beth" item (which now has been selected by typing "b")...
    :
    : Any way around this?
    :

    this might be all happening 'coz of "Sorted=True". See MSDN help for this property which says,
    [code]
    When this property is True, Visual Basic handles almost all necessary string processing to maintain alphabetic order, including changing the index numbers for items as required by the addition or removal of items.

    Note: Using the AddItem method to add an element to a specific location in the list may violate the sort order, and subsequent additions may not be correctly sorted.
    [/code]


  • This is NOT the problem. The alphabetic order is not corrupted in any way. The list shows up with the items correctly sorted, with the rigth index values. The problem mentioned in the MS note, refers to a problem which can occur if you try to add an item to a SPECIFIC location in a sorted list. I do not try to do anything like that.

    I just wonder why the start item is beeing highlighted again after a
    few seconds, when I have left it by typing in a letter - and thereby have moved to another location in the list. (And why the old, highligted item's selected property, now is set to "False" - even if it actual is higlighted - (which it, moreover, should not have been))



    : : Set a ordinary listbox with Sorted=True and Multiselect=2
    : :
    : : Private Sub Form_Load()
    : : List1.AddItem "ann"
    : : List1.AddItem "beth"
    : : List1.Selected(0) = True
    : : End Sub
    : :
    : : Start the program, then type in "b". The second item will be higlighted and selected, as it should, leaving the first one unselected. But - one or two seconds later, the first item is selected again!!!
    : :
    : : Further testing shows that the "ann" item now has the Selected property set to False - even if it (incorrectly) shows up as "selected" - along with the "beth" item (which now has been selected by typing "b")...
    : :
    : : Any way around this?
    : :
    :
    : this might be all happening 'coz of "Sorted=True". See MSDN help for this property which says,
    : [code]
    : When this property is True, Visual Basic handles almost all necessary string processing to maintain alphabetic order, including changing the index numbers for items as required by the addition or removal of items.
    :
    : Note: Using the AddItem method to add an element to a specific location in the list may violate the sort order, and subsequent additions may not be correctly sorted.
    : [/code]
    :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories