BUG: Odd Behavior with Modal Dialog/Form in ListView ItemClick (149268)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
This article was previously published under Q149268 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.
RESOLUTION
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.
| Modification Type: | Major | Last Reviewed: | 6/24/2004 |
|---|
| Keywords: | kbbug kbpending KB149268 |
|---|
|