BUG: ListView Item Not Released after Modal Dialog Dismissed

Last reviewed: October 16, 1996
Article ID: Q150209
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

If a Modal dialog box is invoked in the ItemClick event of a ListItem in the ListView control, and the modal dialog box is dismissed, the item stays attached to the mouse pointer and moving the mouse pointer drags the item.

STATUS

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

WORKAROUND

Do not invoke the modal dialog box directly from the ItemClick event. One alternative is to enable a timer where the modal dialog box is invoked. Set the timer's Enabled property to True and wait in a loop until the dialog box is shown. Then allow the ItemClick event to continue. For example, instead of showing a MsgBox in the ItemClick event for the ListView control, do the following:

   Timer1.Enabled = True

   Do While Timer1.Enabled = True
      DoEvents
      Loop

   'Rest of code follows.

and in the Timer event, invoke the Modal dialog box:

      MsgBox "hi"
      Timer1.Enabled = False

When the modal dialog box is dismissed, the Timer control is disabled. Consequently, the loop in the ItemClick event remains and instructions after the loop are processed only after the modal dialog is dismissed.

To make the modal dialog appear quickly, set the Interval of the Timer control at Design time to a small value such as 100. Also, disable the Timer at Design time so it does not fire an event when the program starts.

Steps To Reproduce the Problem

  1. Start a new project. Form1 is created by default.

  2. Place a ListView control on to Form1. In the Load event of Form1, place the following code to place some items into the control:

          Private Sub Form_Load()
          Dim clmX As ColumnHeader
    

              Dim itmX As ListItem
              Dim i As Integer
              For i = 1 To 3
                  Set clmX = ListView1.ColumnHeaders.Add()
                  clmX.Text = "Col" & i
              Next i
    
              For i = 1 To 10
                  Set itmX = ListView1.ListItems.Add()
                  'itmX.SmallIcon = 1
                  itmX.Text = "ListItem " & i
                  itmX.SubItems(1) = "Subitem 1"
                  itmX.SubItems(2) = "Subitem 2"
              Next i
          End Sub
    
    

  3. In the ItemClick event for the ListView control, place the following code:

          Private Sub ListView1_ItemClick(ByVal Item As ListItem)
    
             Dim s as string
             s = Inputbox("Please enter a string")
             Debug.Print s
          End Sub
    
    

  4. Run the project by pressing F5. Click on a ListView item and a message box appears. Press OK to dismiss the message box and note that the ListItem moves as the mouse is moved.

To use the workaround above on this problem, place a Timer control on the form. Set the Enabled property to False and set the Interval to 100. In the Timer event for the Timer control, place the following code:

   Private Sub timer1_Timer()
      s = Inputbox("Please enter a string")
      timer1.Enabled = False
   End Sub

Place the declaration of the string so it is at the Form level. That is, place the following line of code into the General Declarations section of the Form:

   Dim s As String

Finally, modify the code in the ItemClick event to:

   Private Sub ListView1_ItemClick(ByVal Item As ListItem)
   timer1.Enabled = True
       Do While timer1.Enabled = True
       DoEvents
       Loop
   Debug.Print s
   End Sub

Run the project. Notice that the ListView item does not drag with the mouse pointer after the modal dialog is dismissed. Note that the print out of the strings to the Debug window is correct because this behavior only occurs after the modal InputBox has been dismissed.


Additional reference words: 4.00 vb4win vb432 buglist4.00
KBCategory: kbprg kbbuglist
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 16, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.