BUG: Odd Behavior with Modal Dialog/Form in ListView ItemClick

Last reviewed: October 3, 1996
Article ID: Q149268
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 32-bit only, for Windows, version 4.0

SYMPTOMS

Showing a modal form or dialog box (such as a message box) as a result of code in the ItemClick event of a ListView control can cause odd behavior with the ListView when the modal form or dialog box is dismissed. The ListItem that was clicked often moves around the ListView control and appears to be attached to the mouse pointer.

WORKAROUND

This problem is a result of the modal form interrupting the normal flow of execution. To avoid this problem, do not show any modal forms or dialog boxes in code for the ItemClick event. If the ListView needs to be able to respond to an ItemClick and needs information from the item that was clicked on, one should save the ListItem object passed to the ItemClick event and use it in the Click event for the same ListView control. Any processing that needs to be completed when an item is clicked upon can be performed in the Click event with the saved ListItem object. The following code shows this technique by declaring and using private form-level variable of type ListItem. This variable is set in the ItemClick event (which is fired before the Click event) and then is used in the Click event that is fired immediately after the ItemClick.

   Private itmSaved As ListItem

   Private Sub ListView1_ItemClick(ByVal Item As ListItem)
      Set itmSaved = Item
   End Sub

   Private Sub ListView1_Click()
      MsgBox itmSaved.Text
   End Sub

STATUS

Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce

  1. Start Visual Basic 4.0, 32-bit version. Form1 is created by default.

  2. Add a single ListView control to the form.

  3. Add this code to Form1:

       Private Sub Form_Load()
       ListView1.ListItems.Add , "K1", "hello world"
       End Sub
    
       Private Sub ListView1_ItemClick(ByVal Item As ListItem)
       MsgBox Item.Text
       End Sub
    
    

  4. Press F5 or select Start from the Run menu to start the application. Click on the single ListItem object and choose OK to dismiss the message box. Observe the fact that the ListItem object now appears attached to the mouse pointer and moves with the mouse pointer all over the ListView control.


Additional reference words: 4.00 vb4win vb432
KBCategory: kbprg kbbuglist
KBSubcategory: PrgCtrlsCus



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