05-12-2017 10:28 AM
Can I programmatically select a node in a Tree Control in a SUDialog? Thanks!
Solved! Go to Solution.
05-15-2017 04:57 AM
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
05-15-2017 04:40 PM
Yes, that's perfect, thanks!
09-15-2017 09:51 PM
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
09-25-2017 06:31 AM
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