Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListView to enable (multi-select) Drag-and-Drop

Status
Not open for further replies.

davidmreid

Programmer
Nov 30, 2001
16
US
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
 
Have a look at the FAQ area of the Microsoft: Access Forms forum:
Zameer wrote 3 faqs about ListView and you may send a comment to the author.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I want to expand on his examples by providing Drag-and-Drop functionality.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top