1. PI-MDBTree Tutorial

In this example we illustrate the use of the PI-MDBTree control by adding it to a Visual Basic project. The example demonstrates how to connect to different servers and the utilization of some of the events and properties. The code also demonstrates the drag and drop features and error handling capabilities.

  1. STEP 1. Set up the project

Start Visual Basic and select a new "Standard Exe" project. Follow the instructions described earlier in this chapter on how to add the necessary references and the controls to the project.

  1. STEP 2. Insert controls

From the toolbox, select and place the following controls onto the form

See the screen capture later in this chapter for placement and sizing details.

  1. STEP 3. Set control properties

Select the text box and from the Properties pane, locate the "Multiline" property and change its value to True (note: you may not be able to resize the control before you do this).

  1. STEP 4. Add the code

Paste the following code into the Declarations section right after the "Option Explicit" statement (if present):


' LOAD-EVENT:Setup the the project

Private Sub Form_Load()

Text1.OLEDragMode = 0 ' set OLEDrag/Drop to manual...

Text1.OLEDropMode = 1 ' so that it works for us

End Sub



' User selected a server from the picklist.

' Make an array of server names and set it into the MDB Tree.

Private Sub PISrvPickList1_Click()

Dim serverList(0) As String ' Names array

' get the name of the server and then set the list

serverList(0) = PISrvPickList1.SelectedServer.Name

MDBTree1.setServerList serverList

End Sub


' NODE_SELECTED EVENT: get names and persistence (if available) and display in the text box.

Private Sub MDBTree1_nodeSelectedEvent(rightClick As Boolean, _

selectionType As Integer, treeNode As MDBNode)

Dim message As String

' Create a string that displays all names

' display the node name

message = "You selected: " + treeNode.itemName

' the pathname

message = message + vbNewLine + vbNewLine + _

"Full pathname=" + _

MDBTree1.getFullPathName(treeNode, MDBPATH_FULL)

' show persistence str

message = message + vbNewLine + vbNewLine + _

"PersistenceString=" + _


' finally show the names string

Text1.Text = message

End Sub



' Give feedback if there's something on the clipboard

Private Sub Text1_OLEDragOver(Data As DataObject, _

Effect As Long, Button As Integer, Shift As Integer, _

X As Single, Y As Single, State As Integer)

Dim eff As Long

' init effects

eff = Effect - vbDropEffectCopy - vbDropEffectMove

' Indicate we can accept the drop if the clipboard data

' contains the text format

If Data.GetFormat(vbCFText) Then

eff = vbDropEffectCopy Or eff

End If

' set the return

Effect = eff

End Sub



' This is the textbox OLEDrop, i.e user drags and drops

' items onto the textbox.

' This code attempts to show what's on clipboard in

' three possible formats:

' normal text (node name); PathFormat (full pathname) and

' PersistenceFormat (persistence)

Private Sub Text1_OLEDragDrop(Data As DataObject, _

Effect As Long, Button As Integer, _

Shift As Integer, X As Single, Y As Single)

Dim names As String, paths As String

Dim persistence As String

Dim DragDropObj As New DaDObject

' get object names as standard text

names = Data.GetData(vbCFText)

' Get pathnames if available

If Data.GetFormat(DragDropObj.PathNamesClipboardFormat) Then

' get paths

paths = Data.GetData(DragDropObj.PathNamesClipboardFormat)

' get rid of nulls

paths = Replace(paths, vbNullChar, " ")

End If

' Get persistence strings if available

If Data.GetFormat(DragDropObj.PersistenceClipboardFormat) Then

persistence = Data.GetData(DragDropObj.PersistenceClipboardFormat)

' replace nulls

persistence = Replace(persistence, vbNullChar, " ")

End If

' create a single string out of the previous...

Text1.Text = names + vbNewLine + vbNewLine + paths + _

vbNewLine + vbNewLine + persistence

End Sub


' ERROR_EVENT: show possible errors in the text box.

Private Sub MDBTree1_errorEvent(errMsg As String)

' include time in the error

Text1.Text = Format(Time, "Long Time") + ": " + errMsg

End Sub

  1. STEP 5. Test the control

Save the project and run it. The tree-view should come up and show a single root node for the default server. Expand the tree down to "module" level (expand server and modules nodes at least) and select (click) a module. The text box should show the name, pathname and persistence string of the selected module. Experiment with this by expanding and clicking different nodes.

  1. STEP 6. Other features

The form includes a server picklist-control and you can use it to connect to different servers. Experiment with this by selecting a server from the drop-down list and notice that the tree-view collapses and has a single node for the selected server. Please see the PI-ServerPicklist control for details about the picklist control.

The example code also allows you to drag a tree node onto the text box. Try this with different module nodes and see that the module name, full pathname and persistence strings show up in the text box. The pathnames and persistence strings are empty for certain node type like Modules, Aliases and other collections.

This is how the completed form should appear:

Enabling Operational Intelligence