Drag and Drop from ListView to TreeView 
Author Message
 Drag and Drop from ListView to TreeView

Hi all.

Would someone be able to supply any sample code or point me in the right
direction for resources to find out how you can start to drag from a
ListView and then drop the item on a specific node in a Treeview?

I am using VB6 and Common Controls 6

Thank you

Regards,
Steve.



Sat, 26 Jun 2004 23:26:21 GMT  
 Drag and Drop from ListView to TreeView
If I remember correctly there is a parameter in the event that allows
you to access the dropped object.

ahh yes...
Private Sub ListView1_DragDrop(Source As Control, x As Single, y As Single)

This is the key to the ability to discriminate against drops that you
do not desire...

Heres a full set of code that gives a reasonable example of how to use
basic drag and drop...

I use an Enum to control the stages of the Drag.  You will (likely) not find
an easier mechanism to control this process...

Also, I used the right mouse button to perform the drag, you may want
to use the left, but remember it may get tricky unless you use the report
view(which you may want to consider anyway because it will allow more
than one visible data item per listitem using SubItems (which will
also slightly complicate the add to the treeview, but not greatly...).

Please add the below controls to a new project and paste the code below

    treeview (Treeview1)
    listview (ListView1)
    Label(Label1)

-- Begin Code Snip --
Option Explicit

Private bDragging As Boolean

Private Enum enmDrag
    step1
    step2
    Step3
End Enum

Private Sub Form_Load()

    TreeView1.LineStyle = tvwRootLines
    Dim nodX As Node
    Set nodX = TreeView1.Nodes.Add(, , "r", "Root")
    Set nodX = TreeView1.Nodes.Add("r", tvwChild, "child1", "Child")

    Call ListView1.ListItems.Add(, "LI1", "ListItem 1")
    Call ListView1.ListItems.Add(, "LI2", "ListItem 2")
    Call ListView1.ListItems.Add(, "LI3", "ListItem 3")

End Sub

Private Sub ListView1_DragDrop(Source As Control, x As Single, y As Single)

    If TypeOf Source Is Node Then
        'if source.
    End If

End Sub

Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As
Single, y As Single)

    If Button = vbRightButton Then
        bDragging = enmDrag.step1
        Label1.Caption = "Setup Drag"
    End If

End Sub

Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As
Single, y As Single)

    If Button = vbRightButton Then
        If bDragging = enmDrag.step1 Then

            bDragging = enmDrag.step2
            ListView1.Drag 1
            Label1.Caption = "Begin Drag"

        End If
    End If

End Sub

Private Sub ListView1_MouseUp(Button As Integer, Shift As Integer, x As
Single, y As Single)

    If Button = vbRightButton Then
        bDragging = enmDrag.Step3
        Label1.Caption = "End Drag"
    End If

End Sub

Private Sub TreeView1_DragDrop(Source As Control, x As Single, y As Single)

    If TypeOf Source Is ListView Then
        If Source.Name = "ListView1" Then
            'We have confirmation that this is an acceptable drop source
            Label1.Caption = "Drag and Drop Treeview"

            On Error Resume Next
            TreeView1.Nodes.Add "r", tvwChild, ListView1.SelectedItem.Text,
ListView1.SelectedItem.Text
            Select Case Err.Number
                Case 0
                Case Else
                    Label1.Caption = "This node alread has been added to the
treeview"
            End Select

        End If
    End If

End Sub

Private Sub TreeView1_DragOver(Source As Control, x As Single, y As Single,
State As Integer)

    If TypeOf Source Is ListView Then
        Label1.Caption = "Drag Over Treeview"
    End If

End Sub
-- End Code Snip --

Have Fun!,

D.


Quote:
> Hi all.

> Would someone be able to supply any sample code or point me in the right
> direction for resources to find out how you can start to drag from a
> ListView and then drop the item on a specific node in a Treeview?

> I am using VB6 and Common Controls 6

> Thank you

> Regards,
> Steve.



Sun, 27 Jun 2004 01:30:06 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. drag and drop between listview and treeview

2. Drag n Drop with listviews and treeviews

3. TreeView + ListView +Drag&Drop

4. HELP: treeview, listview drag and drop with SQL-server

5. drag / drop from listview to treeview ...

6. drag and drop listview to treeview

7. Drag′n Drop from treeview to listview

8. Drag & drop action within ListView and Treeview

9. Drag from ListView & Drop in TreeView controls

10. Listview - treeview drag drop

11. Listview - Treeview drag&Drop

12. Drag and Drop w/ListView & TreeView controls

 

 
Powered by phpBB® Forum Software