|
-
Sep 3rd, 2003, 12:51 PM
#1
Thread Starter
Lively Member
Drag and Drop problem
I try to drag items from a listview to a Treeview.
I use the following code but I don't know how to do the folowing points :
1 - Check if data dragged onto the treeview is listview item collection
2 - When dragdrop, retrieving data from the listview item collection dropped
Thanks in advance ;-)
here is my code :
VB Code:
Private Sub ListView1_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag
ListView1.DoDragDrop(ListView1.SelectedItems, DragDropEffects.Copy Or DragDropEffects.Move)
End Sub
Private Sub TreeView1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragOver
Dim Pt As Point
Dim Node As TreeNode
'If Not (TypeOf sender Is ListView.SelectedListViewItemCollection) Then Exit Sub
'If e.Data.GetDataPresent(GetType(System.Windows.Forms.ListView.ListViewItemCollection)) = True Then
Pt = TreeView1.PointToClient(New Point(e.X, e.Y))
Node = TreeView1.GetNodeAt(Pt)
If Microsoft.VisualBasic.Left(Node.Tag, 7) = "AGENT " Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
'End If
End Sub
Private Sub TreeView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop
Dim Result As DialogResult
'popup confirmation du move
Result = MsgBox("Etes vous sure de vouloir transférer les dossier ?", MsgBoxStyle.YesNo, "Transfer dossier")
If Result = DialogResult.No Then Exit Sub
'update agent traitant des dossiers concerné par le nouvel agent
Dim Items As ListView.ListViewItemCollection()
Items = CType(e.Data.GetData(GetType(System.Windows.Forms.ListView.ListViewItemCollection)), ListView.ListViewItemCollection())
'refresh treeview
End Sub
-
Sep 3rd, 2003, 01:27 PM
#2
1 - Check if data dragged onto the treeview is listview item collection
VB Code:
If e.Data.GetDataPresent(GetType(System.Windows.Forms.ListView.ListViewItemCollection)) Then
Although you are passing the SelectedItems into the DragDrop so you should really be checking for the SelectedListViewItemCollection:
VB Code:
If e.Data.GetDataPresent(GetType(ListView.SelectedListViewItemCollection)) Then
'other code here
End If
2 - When dragdrop, retrieving data from the listview item collection dropped
Use the e.Data.GetData to get the SelectedListViewItemCollection in the DragDrop event.
VB Code:
If e.Data.GetDataPresent(GetType(ListView.SelectedListViewItemCollection)) Then
Dim scol As ListView.SelectedListViewItemCollection=CType(e.Data.GetData,ListView.SelectedListViewItemCollection)
'rest of code here
End If
-
Sep 3rd, 2003, 01:42 PM
#3
Thread Starter
Lively Member
Great it works !!!!
thanks a lot
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
|