Results 1 to 7 of 7

Thread: Tree View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Location
    India
    Posts
    2

    Unhappy Tree View

    How do I implement drag and drop in a tree view? Please HELP!!
    Ajay

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    As a Source or Target (or both). Manual or Automatic. What exactly are you trying to do?

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Location
    India
    Posts
    2
    How do I implement drag and drop in a tree view.
    I want to drag a node and place it under another node. ?
    (like dragging friends in a friend list in MSN Messenger)
    HELP!!
    Ajay

  4. #4

  5. #5
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    I got this somewhere, it covers just about every operation of treeviews.
    Attached Files Attached Files

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    You will need to implement the "rules" for your drag operations.
    Here is some sample code, that will hopefully get you started. The Drag/Drop operation is activated by a Right Mouse button. Make sure you set the Treeview's DragIcon property before running the program. It doesn't matter what the icon is.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim objNode As Node
    5.  
    6.     Treeview1.DragMode = vbManual
    7.  
    8.     Set objNode = TreeView1.Nodes.Add(, , "D", "Mike")
    9.     objNode.Expanded = True
    10.    
    11.     Set objNode = TreeView1.Nodes.Add(, , "A", "Alice")
    12.     objNode.Expanded = True
    13.    
    14.     Set objNode = TreeView1.Nodes.Add(, , "M", "Carol")
    15.     objNode.Expanded = True
    16.    
    17.     Call TreeView1.Nodes.Add("D", tvwChild, "C1", "Greg")
    18.     Call TreeView1.Nodes.Add("D", tvwChild, "C2", "Peter")
    19.     Call TreeView1.Nodes.Add("D", tvwChild, "C3", "Bobby")
    20.     Call TreeView1.Nodes.Add("M", tvwChild, "C4", "Marcia")
    21.     Call TreeView1.Nodes.Add("M", tvwChild, "C5", "Jan")
    22.     Call TreeView1.Nodes.Add("M", tvwChild, "C6", "Cindy")
    23.    
    24. End Sub
    25.  
    26. Private Sub Treeview1_DragDrop(Source As Control, x As Single, y As Single)
    27.     Dim objNode As Node
    28.    
    29.     If Source Is TreeView1 Then
    30.        'Make sure there is a Node to at the location
    31.        Set TreeView1.DropHighlight = TreeView1.HitTest(x, y)
    32.         If Not TreeView1.DropHighlight Is Nothing Then
    33.             'Make sure the Source Node is not the Parent of the Target Node and
    34.             'the Source Node is not the Target Node
    35.             If Not TreeView1.DropHighlight.Parent Is TreeView1.SelectedItem And _
    36.                Not TreeView1.DropHighlight Is TreeView1.SelectedItem Then
    37.                 'Moves the Source Node under the Target Node
    38.                 Set TreeView1.SelectedItem.Parent = TreeView1.DropHighlight
    39.             End If
    40.         End If
    41.         'Clean up the Drag operation
    42.         Set TreeView1.DropHighlight = Nothing
    43.         TreeView1.Drag vbEndDrag
    44.    
    45.     End If
    46.  
    47. End Sub
    48.  
    49. Private Sub Treeview1_DragOver(Source As Control, x As Single, y As Single, State As Integer)
    50.    'Will show which node will be used as the Target
    51.    Set TreeView1.DropHighlight = TreeView1.HitTest(x, y)
    52. End Sub
    53.  
    54. Private Sub Treeview1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    55.     Dim objNode As Node
    56.     'Start a Drag operation on a Right Mouse click
    57.     If Button = vbRightButton Then
    58.         'Make sure the Source Node of the Drag operation exists and is selected.
    59.         Set objNode = TreeView1.HitTest(x, y)
    60.         If Not objNode Is Nothing Then
    61.             objNode.Selected = True
    62.             TreeView1.Drag vbBeginDrag
    63.         End If
    64.     End If
    65. End Sub

  7. #7
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by MartinLiss
    Ckick here.
    thanks marty for this link. I saw some wonderfull code there on this site.

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