PRB: DragDrop with ListView Control Fails in MouseMove Event
ID: Q184206
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
SYMPTOMS
In a ListView control, if you have DragMode set to vbManual and attempt to
begin DragDrop within the MouseMove event, the Drag operation will never
begin if the View property is set to either lvwIcon or lvwSmallIcon. The
Drag operation will begin successfully if the View property is set to
lvwList or lvwReport.
CAUSE
Normally, the way to initiate an ordinary DragDrop procedure is to set the
Drag property of the Listview control to vbBeginDrag. This is done by
detecting the state of the left-mouse button. If it is depressed, set the
Drag property accordingly. However, this will not work if you place your
code in the MouseMove event. When the left-mouse button is depressed, the
MouseMove button never fires, which means you can't test for the left-mouse
button's state and consequently are not able to begin the Drag operation.
This is only the case when the Listview control's View property is set to
either lvwIcon or lvwSmallIcon. If it is set to lvwList or lvwReport, the
code works as expected.
RESOLUTION
Add code to begin the Drag operation in the MouseDown event. The event is
always fired when the left-mouse button is clicked.
STATUS
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 Behavior
- Start with a Visual Basic form (Form1) and add four Command Buttons and
two ListView controls.
- Place the following code in the General Declarations section of Form1:
Option Explicit
Private Sub Command1_Click()
ListView1.View = lvwIcon
End Sub
Private Sub Command2_Click()
ListView1.View = lvwSmallIcon
End Sub
Private Sub Command3_Click()
ListView1.View = lvwList
End Sub
Private Sub Command4_Click()
ListView1.View = lvwReport
End Sub
Private Sub Form_Load()
Dim Li As ListItem
Dim colX As ColumnHeader
Set colX = ListView1.ColumnHeaders.Add()
colX.Text = "Field "
colX.Width = ListView1.Width
Set Li = ListView1.ListItems.Add(, , "hello")
Set Li = ListView1.ListItems.Add(, , "hello2")
Set Li = ListView1.ListItems.Add(, , "hello3")
Command1.Caption = "lvwIcon"
Command2.Caption = "lvwSmallIcon"
Command3.Caption = "lvwList"
Command4.Caption = "lvwReport"
End Sub
Private Sub ListView1_MouseMove(Button As Integer, _
Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
Set ListView1.SelectedItem = ListView1.HitTest(x, y)
' In the following line any ICO file will do
ListView1.DragIcon = LoadPicture( _
"C:\program files\devstudio\vb\samples\pguide\calc\calc.ico")
ListView1.Drag vbBeginDrag
End If
End Sub
Private Sub ListView2_DragDrop(Source As Control, x As Single, _
y As Single)
Dim li2 As ListItem
MsgBox "Hello"
Set li2 = ListView2.ListItems.Add(, , Source.SelectedItem.Text)
End Sub
- Run the program by pressing the F5 key.
- Try a Drag procedure with the Listview control set to lvwIcon or
lvwSmallIcon. Note that the mouse pointer is stuck within the Listview
client area. Change the View property to lvwList or lvwReport and note
that the Drag operation works as expected.
Additional query words:
list view drag drop drag drop kbDSupport kbDSD
Keywords : kbVBp500 kbGrpVB
Version : WINDOWS:5.0
Platform : WINDOWS
Issue type : kbprb