Lloyd Sheen said:
Ratnesh,
I am at work right now so I don't have access to my home PC. I do have a
sample of drag and drop of files. It is quite simple but I will post a
little of the code when I get home.
LS
Ratnesh,
Here is some sample code:
The following are variables used for the D&D processsing of mouse moves.
Private _MouseDown As Boolean = False
Private _MouseX As Integer
Private _MouseY As Integer
Private _MouseButtons As MouseButtons
Private _SwitchContext As Boolean = False
The following happens when the mouse button is pressed over my listview
Private Sub List_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles SongFileView.MouseDown
_MouseButtons = e.Button
_SwitchContext = False
_MouseDown = True
_MouseX = e.X
_MouseY = e.Y
End Sub
The following happens on a move of the mouse. I use a test for the distance
the mouse has moved to prevent false drag drop operations:
Private Sub List_MouseMove(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles SongFileView.MouseMove
Dim lv As ListView = DirectCast(sender, ListView)
Dim sc As New StringCollection
If _MouseDown Then
If Math.Abs(_MouseX - e.X) < 5 Or Math.Abs(_MouseY - e.Y) < 5
Then
Exit Sub
End If
Dim xx As DataObject = New DataObject
Dim yy As ArrayList = New ArrayList
For Each idx As Integer In lv.SelectedIndices
Dim li As ListViewItem = lv.Items(idx)
yy.Add(li.SubItems(5).Text + "\" + li.Text)
sc.Add(li.SubItems(5).Text + "\" + li.Text)
Next
Dim zz As Array = yy.ToArray
xx.SetFileDropList(sc)
xx.SetData("ListItems", lv.SelectedItems)
Try
lv.DoDragDrop(xx, DragDropEffects.Copy)
_MouseDown = False
Catch ex As Exception
Dim zzzz As Integer = 1
End Try
End If
End Sub
The following will reset the D&D if the mouse button is release over the
listview:
Private Sub SongFileView_MouseUp(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles SongFileView.MouseUp
_MouseDown = False
End Sub
Hope this helps:
Lloyd Sheen