# Dynamically populating a tree view

**URL:** <https://forum.inductiveautomation.com/t/dynamically-populating-a-tree-view/6814>\
**Category:** Ignition\
**Created:** [July 4, 2013, 1:14am UTC](https://forum.inductiveautomation.com/t/dynamically-populating-a-tree-view/6814 "2013-07-04T01:14:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [July 4, 2013, 1:14am UTC](https://forum.inductiveautomation.com/t/dynamically-populating-a-tree-view/6814/1 "2013-07-04T01:14:54Z")

</div>

I have the python script that is reading files out of a folder, i wanted to dynamically populate a tree view with the data.

What I have done to this point was add a script to the app module that works fine. Then i added an expression to the data/item of the tree view. when it opens i get an error:

`Cannot coerce value 'C:\path\file.csv' into type: interface
`  
I am new to ignition and I’m not sure how to link the two. I was wondering if anyone could point me in the right direction, thx.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [July 4, 2013, 2:18am UTC](https://forum.inductiveautomation.com/t/dynamically-populating-a-tree-view/6814/2 "2013-07-04T02:18:45Z")

</div>

should probably post your scripts and a better example of what you are trying to accomplish. are you trying to read data out of a csv file and use that data to build a dataset for a treeview component?

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [July 4, 2013, 2:32am UTC](https://forum.inductiveautomation.com/t/dynamically-populating-a-tree-view/6814/3 "2013-07-04T02:32:26Z")

</div>

Thanks for the reply, im reading a folder on my C drive, taking the filenames out of the folder and I wanted them to display in the treeview.

Here is my app script:

`def treeList(path = r'C:\folder\\'):
	import os, csv, glob
	#read all the files in a folder
	files = []
	for fileName in glob.glob(os.path.join(path,"*")):
		 files.append(fileName)
	return files`

here is what I have listed in the data \> Items script:

```auto
runScript("app.Tree_View.treeList()")
```

Here is the error I’m getting, it is listing the files but tells me:

```auto
Cannot coerce value '['C:\\folder\\file1.csv', 'C:\\folder\\file2.csv']' into type: interface
```

Thanks

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [July 4, 2013, 6:56pm UTC](https://forum.inductiveautomation.com/t/dynamically-populating-a-tree-view/6814/4 "2013-07-04T18:56:20Z")

</div>

Im guessing its the way im trying to link the data to the tree, does anyone have any experience trying to do this? Thanks

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [July 5, 2013, 12:28pm UTC](https://forum.inductiveautomation.com/t/dynamically-populating-a-tree-view/6814/5 "2013-07-05T12:28:37Z")

</div>

yes you need to take a look at the dataset in the treeview component and make whatever data you are pulling from those files formatted to match that dataset.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [July 5, 2013, 1:41pm UTC](https://forum.inductiveautomation.com/t/dynamically-populating-a-tree-view/6814/6 "2013-07-05T13:41:31Z")

</div>

Thanks Diat150,

I tried formatting my returned values a little, but I am a little unsure how they are supposed to match. I read how I need to have the path along with the name, I believe that those are the only required items. I then changed my python to return (path, name) but it still does not work.

Do i need to keep the names with the value in my script, ie… path =\> ‘c:/folder’, name =\> ‘filename.txt’? I’ll try that next and see if it works but I feel like Im spinning my wheels a little, thanks.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [July 6, 2013, 3:13am UTC](https://forum.inductiveautomation.com/t/dynamically-populating-a-tree-view/6814/7 "2013-07-06T03:13:40Z")

</div>

I have modified my scripts, I now have a button that calls a script module to populate the tree view for now.

My module script:

[code]def treeList(fpath = r’C:\Folder\’):  
import os, csv, glob, system

```
#read all the files in a folder
rows = []
for fileName in glob.glob(os.path.join(fpath,"*")):
	tail, head = os.path.split(fileName) 
	rows.append([tail, head])
 
return rows[/code]

```

button script:

[code]import app

rows = app.treeView.treeList()  
#create event handler  
headers = [“path”, “text”]  
fileList = system.dataset.toDataSet(headers, rows)

# Use our new dataset to fill in a tree view

#treeV = window.rootContainer.getComponent(name)  
treeV = event.source.parent.getComponent(“csvList”)  
treeV.data = fileList[/code]

Error:

[code]Traceback (most recent call last):

File “event:actionPerformed”, line 11, in

java.lang.UnsupportedOperationException

java.lang.UnsupportedOperationException: java.lang.UnsupportedOperationException

```
caused by UnsupportedOperationException

```

Ignition v7.6.1 (b2278)  
Java: Oracle Corporation 1.7.0\_25  
[/code]

I am now getting a different error that I am not sure what to do with. Hopefully someone can chirp in with some direction, thanks.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [July 19, 2013, 2:17pm UTC](https://forum.inductiveautomation.com/t/dynamically-populating-a-tree-view/6814/8 "2013-07-19T14:17:49Z")

</div>

I got it working, but I got a list populating. Ill have to work on the tree view later.
