DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I programmatically select a node in a Tree Control?

Solved!
Go to solution

Can I programmatically select a node in a Tree Control in a SUDialog?  Thanks!

0 Kudos
Message 1 of 5
(2,892 Views)
Solution
Accepted by JuliaDawkins

Hi Julia

The Tree control is a new feature of DIAdem 2017 which will be publish at NI Week 2017. Here is an example how to fill a tree tree and select a node:

Sub Tree1_EventInitialize(ByRef This)
  Call CreateDefaultTree(This)
End Sub
Sub Button1_EventClick(ByRef This)
  Dim oMyNode
  set oMyNode = Tree1.GetNode("saw")
  Set Tree1.SelectedItem = oMyNode
  Tree1.ScrollNodeInView(oMyNode)
End Sub
Sub CreateDefaultTree(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

Hope this helps!

Winfried

0 Kudos
Message 2 of 5
(2,837 Views)

Yes, that's perfect, thanks!

0 Kudos
Message 3 of 5
(2,823 Views)

Thanks Winfried,

 

Selecting a node via a button works for me, but if I try to add the selection as part of the Tree1_EventInitalize, I get an error with the "Tree1.ScrollNodeInView(oMyNode)" line.  What I would like to do is fill a tree AND select a node in the tree's EventInitalize routine, is this possible?  Thanks!

 

Sub Tree1_EventInitialize(ByRef This) 'Created Event Handler
  Call CreateDefaultTree(This)
  Button1.RunClick
End Sub

 

0 Kudos
Message 4 of 5
(2,579 Views)

Hi Julia

 

The tree must first be initialized and displayed. Then you could select a node. So you can do this in the event Dialog_EventInitFinalize:

 

Sub Dialog_EventInitFinalize(ByRef This) 'Erzeugter Event-Handler
  Dim oMyNode
  set oMyNode = Tree1.GetNode("saw")
  Set Tree1.SelectedItem = oMyNode
  Tree1.ScrollNodeInView(oMyNode)
End Sub

Winfried

0 Kudos
Message 5 of 5
(2,529 Views)