Drag &Drop using listView Controls 
Author Message
 Drag &Drop using listView Controls


The following section of code is an attempt at creating an environment that
can support drag and drop between two listview controls (lvClient &

The program initially populates lvClient with files found in a folder
(public_html) on the C: drive. The program then sits and waits for a
mouse_down event in lvClient to initiate the drag and drop sequence.

 The code...

' Form Globals
Option Explicit

Dim filesysobj As New Scripting.FileSystemObject
Dim folderObject As Scripting.Folder
Dim file As Scripting.file

 Dim Item As ListItem

' For initialisation
Private Sub Form_Load()

      Dim s As String
      Dim index As Integer

      'Create FileSystemObject
      Set filesysobj = CreateObject("Scripting.FileSystemObject")
      Set folderObject = filesysobj.GetFolder("C:\public_html1")

      'Initialisation of list control (lvClient)
      Set lvClient.Icons = ilPicSource
      Set lvClient.SmallIcons = ilPicSource
      Set lvClient.ColumnHeaderIcons = ilPicSource

      'Initialisation of list control (lvServer)
      Set lvServer.Icons = ilPicSource
      Set lvServer.SmallIcons = ilPicSource
      Set lvServer.ColumnHeaderIcons = ilPicSource

      'Populate lvClient(listview control) with markers to the files found
in public_html1
      For Each file In folderObject.Files
            lvClient.ListItems.Add , , file.Name, , 1
      Next file
End Sub

' Following functions enable darg and drop between the file list boxes.

Private Sub lvClient_MouseDown(Button As Integer, Shift As Integer, x As
Single, y As Single)
      Set Item = lvClient.HitTest(x, y)
      Item.Selected = True
      If (Button = 1) Then lvClient.OLEDrag
End Sub

Private Sub lvClient_OLEStartDrag(Data As MSComctlLib.DataObject,
AllowedEffects As Long)

      Dim i As Integer
      Dim file

      'Add files to data object that were selected by the user
      For i = 1 To lvClient.ListItems.Count
            If lvClient.ListItems.Item(i).Selected Then
                  file = filesysobj.GetFile("C:\public_html1\" &
                  Data.Files.Add file
            End If

      'Only if we actually added files
      If (Data.Files.Count) Then
            Data.SetData , vbCFFiles
            AllowedEffects = vbDropEffectCopy
      End If
End Sub

Private Sub lvServer_OLEDragOver(Data As MSComctlLib.DataObject, Effect As
Long, Button As Integer, Shift As Integer, x As Single, y As Single, State
As Integer)

      If (Data.GetFormat(vbCFFiles)) Then
            Effect = Effect And vbDropEffectCopy
            Effect = vbDropEffectNone
      End If
End Sub

Private Sub lvServer_OLEGiveFeedback(Effect As Long, DefaultCursors As
      'If effect is copy use a custom cursor
      If Effect = vbDropEffectCopy Then
            DefaultCursors = False
            Screen.MousePointer = imgCopy.Picture
            DefaultCursors = True
      End If
End Sub

Private Sub lvServer_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As
Long, Button As Integer, Shift As Integer, x As Single, y As Single)

      If Data.GetFormat(vbCFFiles) Then
            For i = 1 To Data.Files.Count
                  'lvServer.Add = Data.Files(i)
                  lvServer.ListItems.Add , , Data.Files, , 1
            Next i
      End If
End Sub

Any helpful comments would be appreciated

Chris M.

Sat, 06 Jul 2002 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Drag & Drop using listView Controls

2. Drag-&-drop in listview control??

3. Drag from ListView & Drop in TreeView controls

4. Drag and Drop w/ListView & TreeView controls

5. Drag&Drop from ListView

6. TreeView + ListView +Drag&Drop

7. Subject: ListView Drag & Drop Re-order

8. Listview drag & Drop

9. Drag & Drop in Listviews

10. Q:drag/drop & columns on ListView

11. Listview drag & drop

12. Drag & drop action within ListView and Treeview


Powered by phpBB® Forum Software