MDBTree Methods and Events Example

See Also

In this example, the public methods and events of the MDBTree control are used to manipulate the view.


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.


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 and then click (select) a module. The checkboxes will become visible and the node you selected will be checked. Uncheck that module.


' Tree node (checked) state has changed
Private Sub MDBTree1_nodeCheckedChangedEvent(treeNode As MDBNode)
    Dim pathName As String

    Dim serverNames() as String
    Dim newServers(0 To 0) As String
    pathName = MDBTree1.getFullPathName(treeNode, MDBPATH_FULL)     ' get full pathname for the MDB module
    MDBTree1.ShowCheckBoxes = False        ' make checkboxes visible
    MsgBox "CheckBoxes should now be invisible" + vbNewLine + "We'll create an intentional error"
    ' The following code will delete/reset the tree and the "treeNode" becomes invalid
    serverNames = MDBTree1.ServerList ' remeber which servers we use
    newServers(0) = "NoSuchThing" ' this one should't exist
    MDBTree1.setServerList newServers ' should create an error...
    MDBTree1.setServerList serverNames ' go back...
    MsgBox "The tree is now collapsed"
    MDBTree1.locateModule pathName '
    MsgBox "Tree is now expanded to the node you just checked"
End Sub

' Tree node selected event handler
Private Sub MDBTree1_nodeSelectedEvent(rightClick As Boolean, selectionType As Integer, treeNode As MDBNode)
    Dim pathName As String
    Dim icon As Integer

    Dim selectedNodes As NamedValues ' currently selected tree nodes (this is s collection of MDBNodes)

    Dim multiSelectAllowed As Boolean ' is multiselect on?

    Dim numSelected As Integer ' how many nodes are selected ?

    set selectedNodes = MDBTree1.selectedNodes ' get currently selected nodes (should be at least one)
    numSelected = SelectedNodes.Count    ' number of nodes selected
    multiSelectAllowed = MDBTree1.MultiSelect ' get multiselect status
    pathName = MDBTree1.getFullPathName(treeNode, MDBPATH_FULL) ' get full pathname for the MDB module
    MsgBox "You selected " + treeNode.Text + " node" + vbNewLine + "its pathname = " + pathName
    MDBTree1.ShowCheckBoxes = True     ' make checkboxes visible
    icon = treeNode.Image ' save the icon index
    MDBTree1.setNodeImage pathName, 2 ' change the icon to unused icon
    MsgBox "The tree should have checboxes" + vbNewLine + "Note that the node icon has changed..:"
    MDBTree1.setNodeImage pathName, icon ' change the icon back (could also use the Node directly)
    MDBTree1.setNodeState pathName, True, False        ' check the node
End Sub

' Error event - show the message -
Private Sub MDBTree1_errorEvent(errMsg As String)
    MsgBox "Error occured, the message is:" + vbNewLine + errMsg
End Sub

Enabling Operational Intelligence