TreeView Drag&Drop problems 
Author Message
 TreeView Drag&Drop problems

I've been experiencing some strange behavior when attempting to do
drag&drop operations using the TreeView control. Could someone offer
advice on any or all of the following ??

I'm simply trying to drag one node and move it under another node. So
far this is what I have:

MouseDown - I set the SelectedItem to be TreeView.HitTest(x, y) and
begin dragging (TreeView.Drag vbBeginDrag).

DragDrop - I reset the parent of the selected node to be the new
TreeView.HitTest(x, y).

Problem 1: The NodeClick event never fires. I can't seem to get TreeView
to recognize a Drag&Drop event versus a NodeClick (selection) event. Or
for that matter, an Expand event (when I click on the +/-). Am I doing
something wrong? (As a workaround I've been using the Right mouse button
for drag&drop to prevent the conflict, but I really don't want to do
this.)

Problem 2: The entire TreeView control moves when I drag the mouse.

Any advice would be appreciated!

Nancy



Fri, 22 Oct 1999 03:00:00 GMT  
 TreeView Drag&Drop problems

Nancy,

I was having the same problems and I finally got mine to work.  I am giving
you some of my code, but you will need to go through it to see what you
need.  All of it may not apply to you or the treeview.  I hope this helps.
If you have any questions or problems send me mail.  I think I have given
all the code.  If have left something out let me know.

Eve Peratopoulos

Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
 Dim Pic ' Declare variable.
 Pic = "c:\windows\cursors\cross_1.cur"
 If (Button = vbLeftButton And Shift = vbShiftMask) Or (Button =
vbLeftButton) Then ' Signal a Drag operation.
    indrag = True ' Set the flag to true.
    ' Set the drag icon with the CreateDragImage method.
    TreeView1.DragIcon = TreeView1.SelectedItem.CreateDragImage
    TreeView1.Drag vbBeginDrag ' Drag operation.
    sMovement = "Move"
End If
If (Button = vbLeftButton And Shift = vbCtrlMask) Then
    indrag = True
    TreeView1.DragIcon = LoadPicture(Pic) 'load picture
    TreeView1.Drag vbBeginDrag
    sMovement = "Copy"
End If

End Sub

Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Set nodX = TreeView1.SelectedItem ' Set the item being dragged.

iIndex = Right(nodX.Key, 6)

FindLocation
End Sub

Private Sub TreeView1_DragDrop(Source As Control, X As Single, Y As Single)
Dim iTmpIndex As Long

If TreeView1.DropHighlight Is Nothing Then
    TreeView1.DragIcon = LoadPicture() 'unload picture
    GoTo Cleanup
Else
    'Drag & Drop

    If nodX = TreeView1.DropHighlight Then Exit Sub
    Cls
    iIndex = Right(TreeView1.DropHighlight.Key, 6)
    sType = tmpType
    FindLocation
    tmpBtnTitle = nodX.Text
    Index% = nodX.Index

    If Mid(TreeView1.DropHighlight.Key, 6, 6) <> Mid(nodX.Key, 6, 6) Then
        tmpPId = Mid(TreeView1.DropHighlight.Key, 6, 6)
        If CheckDups Then
            MsgBox "Duplication of " & tmpBtnTitle & "!" & Chr(13) &
Chr(13) & _
                   "The action cannot be completed.", 0 + 64, "Duplication
of Category"
            GoTo Cleanup
        End If
    End If

    cNode = TreeView1.DropHighlight.Index
    pNode = TreeView1.DropHighlight.Parent.Index
    iSiblings = TreeView1.Nodes(pNode).Children

    If iSiblings = 7 And Mid(TreeView1.DropHighlight.Key, 6, 6) =
Mid(nodX.Key, 6, 6) And sMovement = "Move" Then
        GoTo Action
    End If

    If iSiblings >= 7 Then
        MsgBox "Cannot complete the action because the" & Chr(13) & _
               "maximum number of subcategories for" & Chr(13) & _
               TreeView1.DropHighlight.Parent & " is 7.", 0 + 64,
"Validation"
        GoTo Cleanup
    End If

Action:
    If sMovement = "Move" Then  'Move within Drag & Drop
        If Mid(nodX.Key, 6, 6) = "000000" Then
            MsgBox ("Can't move a top level category!")
            GoTo Cleanup

        End If

        sRelationship = "Child"
        sRelation = tvwPrevious
        iNodeIndex = frmDocEditor.TreeView1.DropHighlight.Index
        '**To Modify the record
        lAdd = False
        iIndex = Right(nodX.Key, 6)
        tmpBtnOrder = tmpBtnOrder - 1
         '**To remove the old category
        frmDocEditor.TreeView1.Nodes.Remove nodX.Index

        '**Keeps the index from going out of bounds
        If iNodeIndex > frmDocEditor.TreeView1.Nodes.Count Then
            iNodeIndex = frmDocEditor.TreeView1.Nodes.Count
        End If

        AddCategory ("MoveDragDrop")
        ReSequence ("Btn_Order")
        '**Add sublevels to the TreeView if any
        Call AddMoveCategories(iIndex)

    Else                        'Copy within Drag & Drop
        TreeView1.DragIcon = LoadPicture() 'unload picture
        frmDocEditor.TreeView1.MousePointer = vbHourglass
        '**To Add the record
        lAdd = True
        iNodeIndex = TreeView1.DropHighlight.Index
        sRelationship = "Child"
        sRelation = tvwPrevious
        tmpType = sType
        AddCategory ("CopyDragDrop")
        iNodeIndex = CopyNodeIndex
        If Len(nodX.Key) > 17 Then
            iTmpIndex = Mid(nodX.Key, 13, 6)
        Else
            iTmpIndex = Mid(nodX.Key, 12, 6)
        End If
        Call AddSubCategories(iTmpIndex, iIndex)
        ReSequence ("Btn_Order")
        TreeView1.SelectedItem = nodX
        iNodeIndex = nodX.Index
        frmDocEditor.TreeView1.MousePointer = vbDefault
    End If
End If

Cleanup:
    Set TreeView1.DropHighlight = Nothing
    indrag = False

    frmDocEditor.TreeView1.Refresh
    TreeView1.MousePointer = vbDefault
End Sub



Quote:
> I've been experiencing some strange behavior when attempting to do
> drag&drop operations using the TreeView control. Could someone offer
> advice on any or all of the following ??

> I'm simply trying to drag one node and move it under another node. So
> far this is what I have:

> MouseDown - I set the SelectedItem to be TreeView.HitTest(x, y) and
> begin dragging (TreeView.Drag vbBeginDrag).

> DragDrop - I reset the parent of the selected node to be the new
> TreeView.HitTest(x, y).

> Problem 1: The NodeClick event never fires. I can't seem to get TreeView
> to recognize a Drag&Drop event versus a NodeClick (selection) event. Or
> for that matter, an Expand event (when I click on the +/-). Am I doing
> something wrong? (As a workaround I've been using the Right mouse button
> for drag&drop to prevent the conflict, but I really don't want to do
> this.)

> Problem 2: The entire TreeView control moves when I drag the mouse.

> Any advice would be appreciated!

> Nancy



Sat, 23 Oct 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Drag & Drop with TreeView control

2. TreeView Drag & Drop

3. ole drag&drop of file from an activex/ treeview headache

4. TreeView + ListView +Drag&Drop

5. Treeview - Drag & Drop

6. Drag&Drop from NT Explorer to the treeview control

7. Drag&Drop in treeview

8. TreeView with Drag & Drop

9. Drag&Drop in Treeview with HitTest and DropHighlight

10. TreeView, drag & drop, and OLEStartDrag

11. Drag & Drop in TreeView

12. Drag & Drop of TreeView Node

 

 
Powered by phpBB® Forum Software