# TreeView selectedItem

**URL:** <https://forum.inductiveautomation.com/t/treeview-selecteditem/10717>\
**Category:** General Discussion\
**Created:** [November 2, 2015, 4:32pm UTC](https://forum.inductiveautomation.com/t/treeview-selecteditem/10717 "2015-11-02T16:32:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [November 2, 2015, 4:32pm UTC](https://forum.inductiveautomation.com/t/treeview-selecteditem/10717/1 "2015-11-02T16:32:50Z")

</div>

Hi,  
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  
Regards

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 2, 2015, 8:03pm UTC](https://forum.inductiveautomation.com/t/treeview-selecteditem/10717/2 "2015-11-02T20:03:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [November 2, 2015, 9:33pm UTC](https://forum.inductiveautomation.com/t/treeview-selecteditem/10717/3 "2015-11-02T21:33:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [November 2, 2015, 10:13pm UTC](https://forum.inductiveautomation.com/t/treeview-selecteditem/10717/4 "2015-11-02T22:13:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 2, 2015, 11:50pm UTC](https://forum.inductiveautomation.com/t/treeview-selecteditem/10717/5 "2015-11-02T23:50:11Z")

</div>

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 View.data},
  {Root Container.Tree View.selectedPath})`You’ll need the [Simulation Aids](http://marketplace.inductiveautomation.com/moduledetail?moduleId=93) module to have the view() function in your system 🙂  
The [announcement post](https://inductiveautomation.com/forum/viewtopic.php?f=50&t=14532) also has a demo project you can explore.

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [November 3, 2015, 6:10am UTC](https://forum.inductiveautomation.com/t/treeview-selecteditem/10717/6 "2015-11-03T06:10:55Z")

</div>

> [@KathyApplebaum](#):
>
> getSelectedItem() returns an int. Perhaps you are thinking of getSelectedPath()?

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.

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [November 3, 2015, 1:47pm UTC](https://forum.inductiveautomation.com/t/treeview-selecteditem/10717/7 "2015-11-03T13:47:46Z")

</div>

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.

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