DOCUMENT:Q184206 20-APR-1998 [vbwin] TITLE :PRB: DragDrop with ListView Control Fails in MouseMove Event PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:5.0 OPER/SYS:WINDOWS KEYWORDS:vb5all ====================================================================== --------------------------------------------------------------------- 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 --------------------------- 1. Start with a Visual Basic form (Form1) and add four Command Buttons and two ListView controls. 2. 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 3. Run the program by pressing the F5 key. 4. 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 ====================================================================== 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. Copyright Microsoft Corporation 1998.