Update text in a box based on tree selection

I’m trying to populate a text box with selected text in a tree widget. All I’m getting is undefined. How do you do this?

Hi!

There doesn’t seem to be a way to get the selected value in a tree. E.g., it doesn’t offer “Selected Option Of” like a listbox does.

Instead you’ll have to add an OnSelected interaction to each node of the tree. For example, if you wanted to put the text of the selected node in a text box, you’d say

OnSelected (of tree node)
  set text of (text box) to (value) [[This.text]]

…for each node of the tree.

Note that if the node has children, [[This.text]] returns the text of the node followed by the text of its children nodes, each separated by a line feed. For example, in the stock tree item, [[This.text]] of the first node gives you:

Item 1
Item 1.1
Item 1.2
Item 1.3

If you just want the text of the node itself (e.g., “Item 1”) for a node that has children, use this code:

OnSelected (of tree node with child nodes)
  set text of (text box) to (value) [[This.text.substring(0,This.text.indexOf('\n'))]]

…which returns just the first line.

Note that in Axure 9 you must say…

OnSelected (of tree node with child nodes)
  set text of (text box) to (value) [[This.text.substring(1,This.text.indexOf('\n', 1))]]

…because in Axure 9 a parent node’s text starts with a line feed.

[Edt] Adding sample file: getTreeNodeText.rp (59.9 KB)

1 Like