DIAdem Help

Object: TreeNode

  • Updated2024-09-12
  • 3 minute(s) read

Object: TreeNode

The TreeNode object corresponds to a node in the tree of a user dialog box.

The following example creates a tree. If you click the Button1 button, the example displays the selected entry and its superordinate, neighboring, and subordinate nodes:

Dim sOutPut
Sub Tree1_EventInitialize(ByRef This)
  Dim oRoot, oMainNode
  Set oRoot = This.Nodes.Add("Tools")
  oRoot.Key = "tools"
  oRoot.Expanded = true
  Set oMainNode = oRoot.Nodes.Add("Electric Tools")
  oMainNode.Key = "electric"
  oMainNode.Nodes.Add("Drill").Key = "drill"
  oMainNode.Nodes.Add("Saw").Key = "saw"
  Set oMainNode = oRoot.Nodes.Add("Hand Tools")
  oMainNode.Key = "handtool"
  oMainNode.Nodes.Add("Hammer").Key = "hammer"
  oMainNode.Nodes.Add("Screwdriver").Key = "screwdriver"
  oMainNode.Nodes.Add("Tongs").Key = "tongs"
End Sub

Sub Button1_EventClick(ByRef This)
  Dim oMyNode
  Set oMyNode = tree1.SelectedItem
  If (Not oMyNode Is Nothing) Then
    sOutPut = "Node selected: " & oMyNode.Text & VBCrLf
    If oMyNode.Parent is Nothing Then
      sOutPut = sOutPut & "Node is root node" & VBCrLf
    Else
      sOutPut = sOutPut & "Parent: " & oMyNode.Parent.Text & VBCrLf
    End If
    If oMyNode.PreviousNode is Nothing Then
      sOutPut = sOutPut & "Node is first node" & VBCrLf
    Else
      sOutPut = sOutPut & "Previous node: " & oMyNode.PreviousNode.Text & VBCrLf
    End If
    If oMyNode.NextNode is Nothing Then
      sOutPut = sOutPut & "Node is last node" & VBCrLf
    Else
      sOutPut = sOutPut & "Next node: " & oMyNode.NextNode.Text & VBCrLf
    End If
    If oMyNode.Nodes.Count = 0 Then
      sOutPut = sOutPut & "Node has no children" & VBCrLf
    Else
      sOutPut = sOutPut & "First child: " & oMyNode.Nodes(1).Text & VBCrLf
    End If
  Else
    sOutPut = "No node selected."
  End If
  Call MsgBox(sOutPut)
End Sub

Methods

Update