How to populate Tree View Widget

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
theowright2020
Posts: 7
Joined: Tue Jan 21, 2020 11:50 pm

How to populate Tree View Widget

Post by theowright2020 » Tue Jan 21, 2020 11:57 pm

Hi I am completely new to Livecode,

I am trying to populate a tree view widget using folder structure from disc

User chooses the folder
I create an array from folder data
I have no problem populating a field eg. scrollable list

When i try to populate the tree view widget,
put arrayData into widget "treeview"
Error states that
(Chunk: destination is not a container)

What is the usual method to change the array data within the widget??

Thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to populate Tree View Widget

Post by dunbarx » Wed Jan 22, 2020 12:59 am

Hi.

I don't use widgets, nor do I use LiveCode Builder. So why am I here?

Oh yes, Back in ordinary LC, I would surmise that you cannot put data into a widget, just as, perhaps, you cannot put data into, say, a card.They are not containers. This is pure conjecture.

Someone will answer soon.

You are welcome.

Craig
Last edited by dunbarx on Wed Jan 22, 2020 2:48 am, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to populate Tree View Widget

Post by FourthWorld » Wed Jan 22, 2020 1:37 am

theowright2020 wrote:
Tue Jan 21, 2020 11:57 pm
put arrayData into widget "treeview"
arrayData is the name of the widget property you'll be setting. Given an array named "MyArray", try this:

Code: Select all

set the arrayData of widget "treeview" to MyArray[/p]
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

theowright2020
Posts: 7
Joined: Tue Jan 21, 2020 11:50 pm

Re: How to populate Tree View Widget

Post by theowright2020 » Wed Jan 22, 2020 10:47 am

this is my full command code:


command populateView

repeat with x = 1 to 4
put random(1000) into tArray[x]
end repeat

combine tArray using return and tab

set the arrayData of widget "treeview" to tArray

end populateView



it's still not working, I can print out my array in answer fine, just nothing changes in the arrayData field of the widget
any idea what I'm doing wrong?

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to populate Tree View Widget

Post by bogs » Wed Jan 22, 2020 11:28 am

combine tArray using return and tab

set the arrayData of widget "treeview" to tArray
Why are you combining the array you create, when you are setting arrayData to it?

I could be wrong, but I think you only combine array data to show it in an ordinary field.
Image

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to populate Tree View Widget

Post by Klaus » Wed Jan 22, 2020 2:06 pm

HI Theo,

welcome to the forum!

You had it right, but then wrecked it. 8)
This will do:

Code: Select all

...
repeat with x = 1 to 4
   put random(1000) into tArray[x]
end repeat

## TREEVIES widget NEEDS an ARRAY, so do not destroy the array again!
## combine tArray using return and tab

set the arrayData of widget "treeview" to tArray
...
Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to populate Tree View Widget

Post by dunbarx » Wed Jan 22, 2020 5:48 pm

Bogs.

You are mostly right. The "combine" command changes an array variable into an ordinary variable, the only kind that can be displayed in a field, or in almost any container one wants to actually look at.

The inspector (when viewing custom properties) and the debugger (when stepping through a handler) will elucidate arrays into visible form.

Craig

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to populate Tree View Widget

Post by bogs » Wed Jan 22, 2020 8:31 pm

dunbarx wrote:
Wed Jan 22, 2020 5:48 pm
The inspector (when viewing custom properties) and the debugger (when stepping through a handler) will elucidate arrays into visible form.
The editor has a function scripted to break down an array in the older versions of the IDE as you can see below (not sure about the current one as I tend not to go into it too often).
aPic_EditorArrayFunction.png
Um-hummmm....
...and I suspect the field showing the custom property is similarly broken down *for display purposes*.

The only reason I know of for breaking down an array is therefore to display it in a field, what other reason would you have? For putting individual parts of the array into regular variables? You can already access the individual parts directly from the array :D

I can't imagine a caption for a button requiring an array to be listed, nor a graphic, you sure can't play a tune with one (well, maybe you could, but there are easier ways), but maybe my imagination just isn't up to the task anymore either heh.

In any case, you certainly would not to pass the broken down parts to another function that is expecting to handle an array, I don't think :wink:
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to populate Tree View Widget

Post by dunbarx » Wed Jan 22, 2020 8:48 pm

Bogs.

Not sure I am seeing what you mean in the SE snapshot you posted. The SE creates a black inverted triangle to mark an array. I meant something like this:
Screen Shot 2020-01-22 at 2.47.13 PM.png
Craig

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to populate Tree View Widget

Post by bogs » Wed Jan 22, 2020 9:17 pm

dunbarx wrote:
Wed Jan 22, 2020 8:48 pm
Not sure I am seeing what you mean in the SE snapshot you posted.
The code snapshot posted is what (in the older IDEs) breaks an array down so it can be displayed in this particular group (which may look familiar :D )
aPic_EditorArrayFunctionTreeDisplay.png
I've got a few nuts that fell from my tree...
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to populate Tree View Widget

Post by dunbarx » Wed Jan 22, 2020 9:55 pm

OK, similar to what we have now.

In the current PI:
Screen Shot 2020-01-22 at 3.54.12 PM.png
I use these "tools" all the time to see arrays, as opposed to changing them into ordinary variables and displaying, er, ordinarily.

Craig

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to populate Tree View Widget

Post by bogs » Wed Jan 22, 2020 10:26 pm

Myself as well, mostly to make sure I am creating and populating an array the way I expect it to be. Well, mostly the debugger, unless I am in very early versions of Mc.
Image

Post Reply