这是我写的两个ListView间的拖放操作(LstField为字段名列表,LstOrder为排序字段),但只支持单选,你可以把它改为多选:Dim vDragData As VariantPrivate Sub LstField_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If vDragData = "StartDrap" And Effect = 2 Then
        Dim item As ListItem, i As Long, j As Long
        j = 1
        For i = 1 To lstOrder.ListItems.Count
            If lstOrder.ListItems(i).Selected = True Then
                On Error Resume Next
                Set item = LstField.ListItems.Add(, lstOrder.ListItems(i).Key, lstOrder.ListItems(i).Text): item.Tag = item.Key
                j = j + 1
            End If
        Next i
        
        vDragData = ""
    End If
End SubPrivate Sub LstField_OLEStartDrag(Data As MSComctlLib.DataObject, AllowedEffects As Long)
    AllowedEffects = 2
    vDragData = "StartDrap" 'Data.GetData(vbCFDIB)
    LstField.OLEDropMode = ccOLEDropNone
    lstOrder.OLEDropMode = ccOLEDropManual
End SubPrivate Sub lstOrder_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If vDragData = "StartDrap" And Effect = 2 Then
        Dim item As ListItem, i As Long, j As Long
        j = 1
        For i = 1 To LstField.ListItems.Count
            If LstField.ListItems(i).Selected = True Then
                On Error Resume Next
                Set item = lstOrder.ListItems.Add(, LstField.ListItems(i).Key, LstField.ListItems(i).Text): item.Tag = item.Key
                j = j + 1
            End If
        Next i
        
        vDragData = ""
    End If
End SubPrivate Sub lstOrder_OLEStartDrag(Data As MSComctlLib.DataObject, AllowedEffects As Long)
    AllowedEffects = 2
    vDragData = "StartDrap" 
    lstOrder.OLEDropMode = ccOLEDropNone
    LstField.OLEDropMode = ccOLEDropManual
End Sub

解决方案 »

  1.   

    '要试用本例请在窗体中加入一个ListView和一个按钮及一个PictureBox
    '然后在代码窗体中粘贴如下代码Private Sub Command1_Click()
        '演示确定ListView上多项选择
        Dim ltmEach As ListItem
        
        For Each ltmEach In ListView1.ListItems
            If ltmEach.Selected Then
                MsgBox ltmEach.Text & " 被选取了", vbInformation
            End If
        Next
    End SubPrivate Sub Form_Load()
        '以下属性的设置是为了突出演示的效果
        ListView1.MultiSelect = True
        ListView1.View = lvwReport
        ListView1.LabelEdit = lvwManual
        ListView1.DragMode = vbManual
        '这里随便取了个可能在每个人的机器上都有的图标,目的是为了大家试用时的方便
        '大家可以自己换合适的图标
        ListView1.DragIcon = LoadPicture("c:\windows\winupd.ico")
        
        
        ListView1.ColumnHeaders.Add , , "文件名"
        ListView1.ListItems.Add , , "文件一"
        ListView1.ListItems.Add , , "文件二"
        ListView1.ListItems.Add , , "文件三"End SubPrivate Sub ListView1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            ListView1.Drag
        End If
    End SubPrivate Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
        '演示将ListView上一个记录拖到一个图片(垃圾箱图片)就删掉这个记录怎么编程
        Select Case Source.Name
        Case "ListView1"
            If MsgBox("请确定是否要删除" & ListView1.SelectedItem.Text, vbYesNo + vbQuestion) = vbYes Then
                MsgBox "在这里写你要完成删除功能的代码", vbInformation
            End If
        Case Else
        End Select
    End Sub