i need to implement drag and drop in treeview in VB

Discussion in 'Microsoft VB .NET' started by pooja, Aug 7, 2006.

  1. pooja

    pooja Guest

    i need to implement drag and drop in treeview in VB.
    Kindly help.
    My treeview contains activities maintained using XML Files.
    Hopefully, Thanks.
     
    pooja, Aug 7, 2006
    #1
    1. Advertisements

  2. pooja

    Guest Guest

    Hi Pooja-

    You can implement drag and drop with the DataObject (the "clipboard").

    In the form that hosts the TreeView control (perhaps in the TreeViews
    MouseMove Event):

    Private Sub treeFileInfoTree_MouseMove(ByVal sender As Object, ByVal e As
    System.Windows.Forms.MouseEventArgs) Handles treeFileInfoTree.MouseMove

    Dim tBase as TreeView
    Dim data as New DataObject
    'If no mouse button pressed, then assume no dragdrop
    If e.Button = MouseButtons.None Then Exit Sub
    tBase = DirectCast(sender, TreeView)
    'Exit sub if button pressed but mouse is not over treeview node
    If tBase.SelectedNode.Bounds.Contains(e.X, e.Y) Then Exit Sub
    'Assign data to clipboard
    data.SetData(DataFormats.Text, tBase.SelectedNode.Text)
    'Begin Drag Operation
    Dim effect As DragDropEffects = DragDropEffects.Copy
    effect = tBase.DoDragDrop(data, effect) 'wait here until drop complete

    End Sub

    Then you need to add code to the DragDrop event of the control where the
    drop is occuring:

    Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As
    System.Windows.Forms.DragEventArgs) Handles lstOriginal.DragDrop

    Dim lBase As ListBox = DirectCast(sender, ListBox)
    lBase.Items.Add(e.Data.GetData(DataFormats.Text).ToString)

    End Sub

    "pooja" wrote:

    > i need to implement drag and drop in treeview in VB.
    > Kindly help.
    > My treeview contains activities maintained using XML Files.
    > Hopefully, Thanks.
    >
    >
     
    Guest, Aug 7, 2006
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jiatiejun

    How to HighLight the Drag-Drop Node in TreeView ?

    jiatiejun, Oct 29, 2003, in forum: Microsoft VB .NET
    Replies:
    3
    Views:
    1,060
    Robin Tucker
    Oct 29, 2003
  2. Steven Stein [MSFT]

    RE: Drag and Drop from TreeView Node to a TextBox

    Steven Stein [MSFT], Nov 10, 2003, in forum: Microsoft VB .NET
    Replies:
    0
    Views:
    846
    Steven Stein [MSFT]
    Nov 10, 2003
  3. Wanda
    Replies:
    2
    Views:
    1,037
    Wanda
    Mar 29, 2004
  4. L.M
    Replies:
    3
    Views:
    182
    solex
    Oct 8, 2004
  5. Sindbaad

    How to implement drag n drop events in AXWEBBROWSER

    Sindbaad, Feb 5, 2005, in forum: Microsoft VB .NET
    Replies:
    0
    Views:
    149
    Sindbaad
    Feb 5, 2005
Loading...

Share This Page