BUG: CreateDragImage Method in ListView Uses Wrong Icon

Last reviewed: August 4, 1997
Article ID: Q172057
The information in this article applies to:
  • Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 5.0

SYMPTOMS

When dragging a selection from the ListView control, the icon for the first item in the list is displayed during the drag operation. This problem occurs when the CreateDragImage method is used.

RESOLUTION

To work around this problem, it is necessary to extract the correct icon from the image list that provides the icons for the ListView. For example, if the original line of code reads:

   ListView1.DragIcon = ListView1.SelectedItem.CreateDragImage

change it to read:

   ListView1.DragIcon= _
   ImageList1.ListImages(ListView1.SelectedItem.Index).ExtractIcon

STATUS

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

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new "Standard EXE" project.

  2. On the default form, place an ImageList, a ListView, and a label.

  3. Left-click on the ImageList, select Properties, and use "Insert Picture" to add four different icons to the ImageList.

  4. Place the following code in the Forms module:

    Dim itmX As ListItem

       Private Sub Form_Load()
       Dim i As Integer
       ListView1.Icons = ImageList1
       ListView1.SmallIcons = ImageList1
       For i = 1 To 4
          Set itmX = ListView1.ListItems.Add(i, , "List item " + Str(i), i, i)
       Next
       End Sub
    
       Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, _
          x As Single, y As Single)
       Set itmX = ListView1.SelectedItem ' Set the item being dragged.
       End Sub
    
       Private Sub listView1_MouseMove(Button As Integer, Shift As Integer, _
          x As Single, y As Single)
       If Button = vbLeftButton Then ' Signal a Drag operation.
          Label1.Caption = ListView1.SelectedItem 'Check which item is selected
          ListView1.DragIcon = ListView1.SelectedItem.CreateDragImage
          'workaround
          'ListView1.DragIcon = _
          '  ImageList1.ListImages(ListView1.SelectedItem.Index).ExtractIcon
          ListView1.Drag vbBeginDrag ' Drag operation.
      End If
      End Sub
    
    

  5. Run the project.

  6. Drag a selection from the ListView. Note that the icon used for the drag operation is always the first icon in the ListView control.
Keywords          : vb5all
Version           : 5.0
Platform          : WINDOWS
Issue type        : kbbug


================================================================================


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: August 4, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.