Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Treeview Drag and Drop

Posted on 2001-09-05
8
Medium Priority
?
661 Views
Last Modified: 2011-10-03
I'm using VB 6.0 and am trying to do drag-and-drop with a treeview control.  If you look at the folders section in Windows Explorer you'll be able to see what I'm trying to do.  Basically, I want the user to click on a node in the treeview control and be able to drag that node over top of another node and move it there by releasing the mouse button.  Just like in Windows Explorer.  I've done drag-and-drop before so I know the basics of using the Drag, DragOver, and DragDrop methods, I just don't know how to drag a node from a treeview control to another node in the same treeview control.

Please Help.

- Alex
0
Comment
Question by:Egore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 5

Expert Comment

by:rkot2000
ID: 6458818
i think you need to set a parent node. I have a sample at home I will post tomorrow.
0
 
LVL 1

Expert Comment

by:johnczimm
ID: 6458841
Take a look at this program I wrote awhile back.  I think it will do what you are looking for.
http://home.earthlink.net/~jczimmerman/explorerStyleApp.zip
0
 
LVL 1

Expert Comment

by:johnczimm
ID: 6458845
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Accepted Solution

by:
Julian_K earned 800 total points
ID: 6458942
' Here's an example of how do I do this...
' Don't forget to set the treeview's "MouseIcon" property...

Private nodDragged As Node
Private blnDragging As Boolean

Private Sub TreeView1_DragDrop(Source As Control, x As Single, y As Single)
    On Error GoTo L_ErrHandler
   
    'if not dropped over any of the nodes or over itself, then drop the node
    If Not (TreeView1.DropHighlight Is Nothing) Then
        If Not (nodDragged Is TreeView1.DropHighlight) Then
            Set nodDragged.Parent = TreeView1.DropHighlight
        End If
    End If
   
    'release objects
    Set TreeView1.DropHighlight = Nothing
    Set nodDragged = Nothing
    blnDragging = False
   
Exit Sub
'If trying to drop the node over it's own child...
L_ErrHandler:
    If Err.Number = 35614 Then
        MsgBox "Circular reference not allowed!"
        Resume Next
    End If
End Sub

'Lit the node beneath the mouse
Private Sub TreeView1_DragOver(Source As Control, x As Single, y As Single, State As Integer)
    Set TreeView1.DropHighlight = TreeView1.HitTest(x, y)
End Sub

'prepare to move the node.
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 1 Then
        Set nodDragged = TreeView1.HitTest(x, y)
    Else
        Set nodDragged = Nothing
    End If
End Sub

'initialize drag-drop process
Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    If blnDragging Then Exit Sub
    If Button <> 1 Then Exit Sub
    TreeView1.DragIcon = TreeView1.MouseIcon
    blnDragging = True
    TreeView1.Drag vbBeginDrag
End Sub
0
 
LVL 3

Expert Comment

by:adg
ID: 6459101
Learning
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6459128
Listening...
0
 
LVL 3

Author Comment

by:Egore
ID: 6459273
You all started posting about 5 minutes after I left the office, argh! :)  Anyway, I did this a couple years back and Julian K's answer looks right.  I will be implementing this tomorrow morning, so I will definately give the thumbs up or thumbs down by noon (EST) tomorrow.

Thanks!

- Alex
0
 
LVL 3

Author Comment

by:Egore
ID: 6460566
This worked like an absolute charm!  I changed the name of the TreeView control and it worked without a hitch, thanks!

- Alex
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question