Results 1 to 3 of 3

Thread: Drag and Drop problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    68

    Unhappy 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:
    1. Private Sub ListView1_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag
    2.         ListView1.DoDragDrop(ListView1.SelectedItems, DragDropEffects.Copy Or DragDropEffects.Move)
    3.  
    4.     End Sub
    5.  
    6.  
    7.     Private Sub TreeView1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragOver
    8.         Dim Pt As Point
    9.         Dim Node As TreeNode
    10.  
    11.         'If Not (TypeOf sender Is ListView.SelectedListViewItemCollection) Then Exit Sub
    12.         'If e.Data.GetDataPresent(GetType(System.Windows.Forms.ListView.ListViewItemCollection)) = True Then
    13.         Pt = TreeView1.PointToClient(New Point(e.X, e.Y))
    14.         Node = TreeView1.GetNodeAt(Pt)
    15.         If Microsoft.VisualBasic.Left(Node.Tag, 7) = "AGENT  " Then
    16.             e.Effect = DragDropEffects.Move
    17.         Else
    18.             e.Effect = DragDropEffects.None
    19.         End If
    20.         'End If
    21.     End Sub
    22.  
    23.     Private Sub TreeView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop
    24.         Dim Result As DialogResult
    25.         'popup confirmation du move
    26.         Result = MsgBox("Etes vous sure de vouloir transférer les dossier ?", MsgBoxStyle.YesNo, "Transfer dossier")
    27.         If Result = DialogResult.No Then Exit Sub
    28.         'update agent traitant des dossiers concerné par le nouvel agent
    29.         Dim Items As ListView.ListViewItemCollection()
    30.         Items = CType(e.Data.GetData(GetType(System.Windows.Forms.ListView.ListViewItemCollection)), ListView.ListViewItemCollection())
    31.         'refresh treeview
    32.     End Sub

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    1 - Check if data dragged onto the treeview is listview item collection
    VB Code:
    1. 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:
    1. If e.Data.GetDataPresent(GetType(ListView.SelectedListViewItemCollection)) Then
    2. 'other code here
    3. 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:
    1. If e.Data.GetDataPresent(GetType(ListView.SelectedListViewItemCollection)) Then
    2. Dim scol As ListView.SelectedListViewItemCollection=CType(e.Data.GetData,ListView.SelectedListViewItemCollection)
    3. 'rest of code here
    4. End If

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    68
    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
  •  



Click Here to Expand Forum to Full Width