Microsoft KB Archive/189733

= BUG: Setting Windowless ListBox ListIndex Fires Click Event =

Article ID: 189733

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q189733



SYMPTOMS
When you programmatically select an item from a Windowless ListBox control, the control's Click event is fired regardless of which item was previously selected. This behavior differs from the standard ListBox control where programmatically reselecting an item does not result in a Click event.

The behavior of selection through the use of the mouse is not affected and is consistent between these two controls.



RESOLUTION
To work around this behavior, check to see if the value that you are about to assign to the ListIndex matches the current ListIndex's value, and make the assignment only if these values differ. See step 10 in the MORE INFORMATION section of this article for an example.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps To Reproduce Problem
 Create a new Standard EXE project. Form1 is created by default. On the Project menu, click Components and add a reference to the "Microsoft Windowless Controls." Add a Standard ListBox to Form1. Add a Windowless ListBox to Form1. Add a CommandButton to Form1.  Paste the following code into Form1's code window: Private Sub Form_Load ' Add some items to the lists List1.AddItem "test" List1.AddItem "test1" WLList1.AddItem "test" WLList1.AddItem "test1" End Sub

Private Sub Command1_Click ' Select the first item in both lists List1.ListIndex = 0 WLList1.ListIndex = 0 End Sub

Private Sub List1_Click Debug.Print "List1.Click" End Sub

Private Sub WLList1_Click Debug.Print "WLList1.Click" End Sub </li> Run the sample project.</li> Click the CommandButton. The click events for both list controls are executed and the results are displayed in the debug window.</li> Click the CommandButton again. Only the click event for the Windowless ListBox control is executed.</li>  Replace the code from step 6 with the following to demonstrate a workaround that makes use of a custom property: Private Sub Form_Load ' Add some items to the lists List1.AddItem "test" List1.AddItem "test1" WLList1.AddItem "test" WLList1.AddItem "test1" End Sub

Private Sub Command1_Click ' Select the first item in both lists List1.ListIndex = 0

' Call custom property to set windowless listindex SetListIndex = 0 End Sub

Private Sub List1_Click Debug.Print "List1.Click" End Sub

Private Sub WLList1_Click Debug.Print "WLList1.Click" End Sub

Private Property Let SetListIndex(NewListIndex As Long) ' Check if selection changed If NewListIndex <> WLList1.ListIndex Then WLList1.ListIndex = NewListIndex End If     End Property </li> Repeat steps 7 through 9. In step 9, note that neither click event is executed.</li></ol>

Additional query words: kbDSupport kbDSD Lightweight kbVBp kbVBp600bug kbCtrl kbDSupport

Keywords: kbbug KB189733

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.