# Recursive scan for leaf nodes on selected treeview parent nodes

**URL:** <https://forum.inductiveautomation.com/t/recursive-scan-for-leaf-nodes-on-selected-treeview-parent-nodes/18164>\
**Category:** Ignition\
**Tags:** ignition78\
**Created:** [May 25, 2018, 2:08am UTC](https://forum.inductiveautomation.com/t/recursive-scan-for-leaf-nodes-on-selected-treeview-parent-nodes/18164 "2018-05-25T02:08:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjamin.f.mcneill](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@benjamin.f.mcneill](https://forum.inductiveautomation.com/u/benjamin.f.mcneill)\
**Post date:** [May 25, 2018, 2:08am UTC](https://forum.inductiveautomation.com/t/recursive-scan-for-leaf-nodes-on-selected-treeview-parent-nodes/18164/1 "2018-05-25T02:08:07Z")

</div>

Hello,

I have a treeview populated from a sql query that is only two layers deep. I have the ability to pass a multiselection to a querie’s where clause but I am not able to get the children of a parent node. Do I need to write the recursion in python or is there a built in way to get children when the selected item = -1?

code for pulling multi select values when each child is selected:

```auto
tv = event.source.parent.getComponent('tv')

def get_list():
	item_list = []
	if event.source.selectedItem != -1:
		selection = tv.getSelectedItems()		
		for item in selection:
			item_list.append("'"+tv.data.getValueAt(item,"AccCode")+"'")
	else
		print event.source.selectedItem
	return ','.join(item_list)

filter = get_list()
if len(filter) > 0:
	event.source.parent.gl_acc_list = filter
		

```

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [May 31, 2018, 5:51pm UTC](https://forum.inductiveautomation.com/t/recursive-scan-for-leaf-nodes-on-selected-treeview-parent-nodes/18164/2 "2018-05-31T17:51:03Z")

</div>

I think you’ll need to write your own logic for getting each sub-item of your selection in the tree.

You might not need a recursive solution for getting the children of implicitly defined ‘folder’ parent nodes though.  
Just search the dataset for all paths that begin with the selectedPath property of the TV.

---

<div class="post-metadata">

**Author:** ![benjamin.f.mcneill](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@benjamin.f.mcneill](https://forum.inductiveautomation.com/u/benjamin.f.mcneill)\
**Post date:** [June 4, 2018, 3:46pm UTC](https://forum.inductiveautomation.com/t/recursive-scan-for-leaf-nodes-on-selected-treeview-parent-nodes/18164/3 "2018-06-04T15:46:13Z")

</div>

Thanks, that is the path I am moving towards.
