|
-
Nov 11th, 2002, 10:57 AM
#1
Thread Starter
Fanatic Member
Drag-all in a ListView, and how to constrain to a box
I have multi select on, and I can select as much items as I want, but how do I drag a lot at once?
Another question (listview), How do I make it so you can only drag in the boxed area of the Listview, by default, the user can keep dragging the item and the listview just gets scroll bars.
-
Nov 11th, 2002, 11:29 AM
#2
Here's a simple method for utilizing multi drag drop capability.
By using the OLE Drag/Drop functionality, the control will behave
like it would in any other Windows application.
VB Code:
Private Sub Form_Load()
Dim lIndex As Long
' Generate 10 Items in the Listview
With ListView1
' Turn on MultiSelect and OLEDragMode
.MultiSelect = True
.OLEDragMode = ccOLEDragAutomatic
For lIndex = 1 To 10
.ListItems.Add , "Key" & lIndex, "Item " & lIndex
Next
End With
' Turn on OLEDropMode for the Listbox
List1.OLEDropMode = vbOLEDropManual
End Sub
Private Sub ListView1_OLESetData(Data As MSComctlLib.DataObject, DataFormat As Integer)
' Store a list of Item "Key" values as the Drag Data
Dim oItem As ListItem
Dim sList As String
' Step through each selected ListView Item
' Adding it's Unique Key to the Delimited List
For Each oItem In ListView1.ListItems
If oItem.Selected Then
sList = sList & "," & oItem.Key
End If
Next
' Set the drag Data to the Delimited string, inserting
' The Listview name as the 1st element for identification.
Call Data.SetData("ListView1" & sList, vbCFText)
End Sub
Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
' When something is dropped on the Listbox..
Dim vItem As Variant
Dim sSource As String
Dim lIndex As Long
' Check to see if the Data is "Text"
If Data.GetFormat(vbCFText) Then
' Extract the text and split it using a comma delimiter
sSource = Data.GetData(vbCFText)
vItem = Split(sSource, ",")
' If the 1st item in the delimited list is the name of the ListView
' Then it's a valid OLE Drag Source
If vItem(0) <> "ListView1" Then Exit Sub
' Clear the Listbox
List1.Clear
' Step through each item in the delimited list
' Using the Key value to locate the appropriate ListView Item
' And add it's text to the Listbox
For lIndex = 1 To UBound(vItem)
List1.AddItem ListView1.ListItems(vItem(lIndex)).Text
Next
End If
End Sub
The only drawback would be that you have limited control over
the drag icon, plus the data is also available to any other
OLE Drag/Drop enabled application.
You could implement something similar using the application Drag/Drop
functionality, however it would be a bit more work - depends on your needs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|