Microsoft KB Archive/172057
Article ID: 172057
Article Last Modified on 11/5/2003
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
This article was previously published under Q172057
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.
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
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Basic 6.0.
Steps to Reproduce Behavior
- Create a new "Standard EXE" project.
- On the default form, place an ImageList, a ListView, and a label.
- Set the View property of the ListView control to "2-lvwList."
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
- Run the project.
- Drag a selection from the ListView. Note that the icon used for the drag operation is always the first icon in the ListView control.
Additional query words: kbVBp500bug kbVBp600fix kbVBp kbdsd kbDSupport kbControl kbCreate
Keywords: kbbug kbfix KB172057