davidmreid
Programmer
Help in enhancing ListView example to enable (multi-select) Drag-and-Drop functionality? Listed below is a double click event on the listview that populates a second listbox:
Private Sub ListView1_DblClick()
' User Double Clicked on a Row
' If FieldList = 0 Then
' Move Selected Items from ListBox1 to ListBox2
' ItemClick event not working, so:
Dim ndx As Integer
Dim itm1 As ListItem
Set itm1 = ListView1.SelectedItem
ndx = itm1.Index
MOVE_SELECTED ListView1, ListView2, ndx
' EndIf
End Sub
Private Sub MOVE_SELECTED(Source As Object, destination As Object, ndx As Integer)
' Move Selected Items from Source ListBox to Destination ListBox
Dim lstItem1 As ListItem
Dim lstItem2 As ListItem
Dim itm1 As ListItem
Dim itm2 As ListItem
Dim intIndex As Integer
Dim strText() As String
Dim i As Integer
On Error Resume Next
With ListView1
' For i = .ListItems.Count To 1 Step -1
ReDim strText(.ColumnHeaders.Count + 1)
Set itm1 = .SelectedItem
Set itm2 = Me.ListView2.ListItems.Add()
itm2.Text = itm1.Text
For intIndex = 1 To .ColumnHeaders.Count - 1
strText(intIndex) = itm1.SubItems(intIndex)
If intIndex = 1 Then
itm2.Text = strText(intIndex)
strText(0) = strText(intIndex)
End If
itm2.SubItems(intIndex - 1) = strText(intIndex)
Next intIndex
ListView1.ListItems.REMOVE (ndx)
ListView1.Refresh
End With
Private Sub ListView1_DblClick()
' User Double Clicked on a Row
' If FieldList = 0 Then
' Move Selected Items from ListBox1 to ListBox2
' ItemClick event not working, so:
Dim ndx As Integer
Dim itm1 As ListItem
Set itm1 = ListView1.SelectedItem
ndx = itm1.Index
MOVE_SELECTED ListView1, ListView2, ndx
' EndIf
End Sub
Private Sub MOVE_SELECTED(Source As Object, destination As Object, ndx As Integer)
' Move Selected Items from Source ListBox to Destination ListBox
Dim lstItem1 As ListItem
Dim lstItem2 As ListItem
Dim itm1 As ListItem
Dim itm2 As ListItem
Dim intIndex As Integer
Dim strText() As String
Dim i As Integer
On Error Resume Next
With ListView1
' For i = .ListItems.Count To 1 Step -1
ReDim strText(.ColumnHeaders.Count + 1)
Set itm1 = .SelectedItem
Set itm2 = Me.ListView2.ListItems.Add()
itm2.Text = itm1.Text
For intIndex = 1 To .ColumnHeaders.Count - 1
strText(intIndex) = itm1.SubItems(intIndex)
If intIndex = 1 Then
itm2.Text = strText(intIndex)
strText(0) = strText(intIndex)
End If
itm2.SubItems(intIndex - 1) = strText(intIndex)
Next intIndex
ListView1.ListItems.REMOVE (ndx)
ListView1.Refresh
End With