PRB: ListView ItemClick Event Executes Multiple Times

Last reviewed: January 5, 1998
Article ID: Q178753
The information in this article applies to:
  • Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 5.0

SYMPTOMS

The ItemClick Event in a ListView control executes multiple times when an item is selected with a single mouse click.

RESOLUTION

To work around this problem, use a Boolean value to allow only one event to execute per single click. This method is illustrated in the MORE INFORMATION section of this article.

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.

MORE INFORMATION

This following steps show you how to create a project that reproduces this problem and how to workaround it.

Step-by-Step Example

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

  2. Add a reference to the Microsoft Common Controls 5.0 by completing the following steps:

    a. From the Project menu, click Components to display the Components

          dialog box.
    

    b. Check Microsoft Common Controls 5.0 and click OK.

  3. Add a ListView control to Form1:

          Option Explicit
    

          Public bToggle As Boolean     'Boolean Flag
    
          Private Sub Form_Load()
          'Adds items to the ListView control
              ListView1.View = lvwList
              ListView1.ListItems.Add , , "Test1"
              ListView1.ListItems.Add , , "Test2"
              ListView1.ListItems.Add , , "Test3"
              ListView1.ListItems.Add , , "Test4"
              ListView1.ListItems.Add , , "Test5"
              ListView1.ListItems.Add , , "Test6"
              ListView1.ListItems.Add , , "Test7"
          End Sub
    
          Private Sub ListView1_ItemClick(ByVal Item As ComctlLib.ListItem)
          'This event only occurs if the Boolean flag is True.
             If bToggle = True Then
                'Comment all lines in this event except for the following
                'line to reproduce the bug.
                MsgBox ListView1.SelectedItem.Text
             End If
             bToggle = False
          End Sub
    
          Private Sub ListView1_MouseDown(Button As Integer, _
                                        Shift As Integer, _
                                        x As Single, _
                                        y As Single)
            'Set the Boolean flag to True. Comment the following line
            'to reproduce the bug.
             bToggle = True
          End Sub
    
    

  4. If you want to reproduce the behavior, comment the appropriate lines. Otherwise, on the Run menu, click Start or press the F5 key to start the program. Click on an item in the ListView control to display a message box. Click OK to close the message box. If the appropriate lines were commented, the message box displays a second time. The correct behavior is the message box displays only once.
Keywords          : vb5all
Version           : WINDOWS:5.0
Platform          : WINDOWS
Issue type        : kbprb


================================================================================


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: January 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.