Incorrect ListIndex when Multiselect Set to 1 or 2

Last reviewed: October 30, 1995
Article ID: Q138524
The information in this article applies to:
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0

SYMPTOMS

If the Multiselect property of a list box is set to Simple or Extended (1 or 2), the ListIndex property returns 0 for an empty list box or a filled list box with nothing selected. It should return -1. When the Multiselect property of a list box is set to 0 (None), the ListIndex correctly returns -1 under these same conditions.

WORKAROUND

To detect whether the first item in a list box is selected, with Multiselect set to 1 or 2, test the Selected property as well as the Listindex property. For example, with multiselect set to 1 or 2, the following code will give a message box only if the first item in the list box is selected:

   If (List1.Selected(0) = True And List1.ListIndex = 0) Then
      MsgBox "First Item Selected"
   End If

STATUS

Microsoft has confirmed this to be a bug in Visual Basic Version 3.0 for Windows. This problem was corrected in Visual Basic Version 4.0.

MORE INFORMATION

Steps to Reproduce Problem

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Place a list box on Form1. Highlight the list box and press the F4 key to bring the Properties window to the foreground. Change the MultiSelect property to 1-Simple.

  3. In the Activate event for Form1, place this code:

    For I = 1 to 10

          List1.AddItem I
    
    Next MsgBox List1.ListIndex

  4. Press the F5 key to start the program. The form returns a message box containing the value 0. The value should be -1 because nothing is selected.


Additional reference words: 3.00 buglist3.00 fixlist4.00
KBCategory: kbprg kbprb kbbuglist kbfixlist
KBSubcategory: PrgCtrlsStd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 30, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.