# Multi select in tree on reload

**URL:** <https://forum.inductiveautomation.com/t/multi-select-in-tree-on-reload/10637>\
**Category:** Ignition\
**Created:** [October 20, 2015, 11:15am UTC](https://forum.inductiveautomation.com/t/multi-select-in-tree-on-reload/10637 "2015-10-20T11:15:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stokstaart](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@stokstaart](https://forum.inductiveautomation.com/u/stokstaart)\
**Post date:** [October 20, 2015, 11:15am UTC](https://forum.inductiveautomation.com/t/multi-select-in-tree-on-reload/10637/1 "2015-10-20T11:15:36Z")

</div>

Dear all,  
i am facing a challenge in which i hope someone can help me.

I am building a tree interface trough a SQL query, and manipulated by python to create a tree like:  
Exhaust  
-temp1  
-temp2  
-temp3  
Pressure  
-pressure1  
-pressure2

Now this builds fine, the problem arises when i have selected multiple values (it’s used as input for a graph) and i rebuild the tree.

Trough the setSelectedItem() i can set one value/row selected but not multiple. I found some documentation in this forum but they are all regarding Tables, not trees…

Does anyone have any idea on how to script a multi selection on a tree??

---

<div class="post-metadata">

**Author:** ![PerryAJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/perryaj/32/3281_2.png) [@PerryAJ](https://forum.inductiveautomation.com/u/PerryAJ)\
**Post date:** [October 20, 2015, 3:15pm UTC](https://forum.inductiveautomation.com/t/multi-select-in-tree-on-reload/10637/2 "2015-10-20T15:15:33Z")

</div>

You’ll want to use the ‘setSelectionRows()’ method of the underlying tree component. Here is a little code snippet that I set on a button to select a couple items on a default Vision Tree View component.

```auto
from javax.swing.tree import TreeSelectionModel

# get the underlying tree component
tree_component = event.source.parent.getComponent('Tree View').getComponent(0).getComponent(0)

#set our selection model to allow discontiguous selection (e.g., select rows 1 and 3 but not 2)
tree_component.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION)

# the rows we want to select
selected_rows = [2,4]

# now apply the selection to the component
tree_component.setSelectionRows(selected_rows)
```

You’ll just need to work your selection logic into populating a list like ‘selection\_rows’. Hope this helps!
