Copy and Paste using DaDObject Example

See Also

In this example, one or more MDBTree nodes are copied and pasted onto the example form in all available formats.

 

Create a new Visual Basic project. Add the PI-MDBTree Control component to the project, and add a reference to the PISDK Type Library. Drop a PI-MDBTree  control onto a new form. Size the control so that it can show few tree nodes. Add three (3) standard textboxes and make them fairly large. Change the following properties for all the textboxes:

- MultiLine = True

Paste the code into the Declarations section. Run the project. The form should come up with a single tree node for the default server (make sure that that default server is available). Expand the tree (modules-branch) few levels down, click (select) a module and then copy it (CTRL + C ). Select textbox Text1 and press CTRL + V. The text for the three textboxes should now be as follows: Text1 = name of the module, Text2 = full pathname of the module, Text3 = persistence string of the module. You can also drag multiple nodes at a time (keep CTRL key down while selecting).

' This example uses Copy and Paste (CTRL C and CTRL V). DaDObject is used to get the data from the clipboard
Private Sub Text1_KeyPress(KeyAscii As Integer)
    Dim DragDropObj As New MDBTreeCtl.DaDObject ' create temporary object

    If KeyAscii = 22 Then ' this seems to be CTRL + V
        If DragDropObj.IsPersistenceOnClipboard Then ' check for the format...
            Text3.Text = makeStringFromArray(DragDropObj.GetPersistenceStringsFromClipboard()) ' get paths
        End If
        If DragDropObj.IsPathNamesOnClipboard Then ' check formats...
            Text2.Text = makeStringFromArray(DragDropObj.GetPathNamesFromClipboard()) ' get persistene
        End If
    End If
End Sub


' Helper that converts string array to a single single
Private Function makeStringFromArray(inArray() As String)
    Dim idx As Integer
    Dim result As String

    On Error Resume Next
    idx = LBound(inArray)
    If Err.Number Then Exit Function
        For idx = idx To UBound(inArray)
            If idx <> LBound(inArray) Then result = result + vbNewLine
                result = result + inArray(idx)
        Next
    makeStringFromArray = result
End Function
 

Enabling Operational Intelligence