Reusable method to perform Drag and Drop operation on a TreeView object using TestPartner

0 Likes
over 8 years ago

There currently does not exist a drag and drop method in TestPartner, however, we are able to use the SelectItem method and the tpMouseDown and tpMouseUp actions to simulate a drag and drop operation on a TreeView item.

Below is function 'DragDropTreeView' that performs the operation:

' Function to drag and drop TreeView items
Public Function DragDropTreeView(ByVal TreeView As TTreeView, ByVal BeginDrag As String, ByVal EndDrag As String) As Boolean
On Error GoTo Err
      ' Select element to drag
      TreeView.SelectItem BeginDrag, tpMouseDown
      ' Select item where the element will be placed
      TreeView.SelectItem EndDrag, tpMouseUp
      DragDropTreeView = True
Err:
      If Err.Number <> 0 Then
            msg = "Error # " & Str(Err.Number) & " was generated by " _
            & Err.Source & Chr(13) & Err.Description
            MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext
            DragDropTreeView = False
      End If
End Function

Below is an example subroutine that uses the above function to perform a drag and drop operation on a node item 'Item-C' that exists in parent node 'Node-1' to its new position in 'Node-3':

' Example Drag and Drop
Sub ExampleDragDrop()
      ' TreeView has the following items
      ' \Node-1, \Node-1\Item-A, \Node-1\Item-B, \Node-1\Item-C
      ' \Node-2, \Node-2\Item-A, \Node-2\Item-C
      ' \Node-3, \Node-3\Item-A, \Node-3\Item-B


      ' Attach to Tree View Window
      Window("Tree View Window").Attach

      ' Drag and drop tree items
      Call DragDropTreeView(TreeView("Label='The Tree View'"), "\Node-1\Item-C", "\Node-3")
End Sub

Labels:

Support Tip
Comment List
Anonymous
Related Discussions
Recommended