TreeView selectedItem

I would like to know the selected record of the dataset behind the treeview (the dataset which is bound to the Items property), when a new item is selected. I saw that when the user select a new leaf, the proprtyChange event of the TreeView fires and the event.propertyName of the changed property is selectedItem. But nowhere I found any documentation on the fields of the selectedItem object (concerning documentation: please improvement is needed).

Thank you in advance

The selectedItem property is the row number in the dataset of that leaf item. When no leaf is selected, it’s -1.

But if you print it you get the full path down to the leaf, not a number, hence my question.

getSelectedItem() returns an int. Perhaps you are thinking of getSelectedPath()?

Ah. I’m often interested in the rows that are involved when a folder node is selected. I use the following expression to extract the rows of interest into a new dataset (custom) property:view("Select path, text, _r Where ('%s/%s' % (path, text)).startswith(args[0])", {Root Container.Tree}, {Root Container.Tree View.selectedPath})You’ll need the Simulation Aids module to have the view() function in your system :slight_smile:
The announcement post also has a demo project you can explore.

I am just speaking about the propertyChange event of the Treeview: when it is fired and inside the event handler you see that the property that caused the event to fire is “selectedItem”, then if you print the newValue of the property out to the console, you get the full path of the selected item down to the leaf and not its row number in the dataset.

In the selectedItem property change event, event.newValue will be the integer row index of the selected row of the underlying dataset. Try the following script.

if event.propertyName == "selectedItem":
	print event.newValue
	ds =
	print ds.getValueAt(event.newValue, 0)