Guidance Forums / Reginald Rexx / Dynamically add a branch to a TREE

Search 搜索
Home Home

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Dynamically add a branch to a TREE
Posted by: mestrini 2007-06-27 00:39:58 Last edited by: Jeff Glatt 2007-07-03 08:30:35 (Total edited 1 time)
How can i dynamically add a 'branch' (child or parent) to a TREE control? Placing it at a specific branch/level? Without wiping out the current contents of the tree?
Posted by: Jeff Glatt 2007-06-27 15:34:54 Last edited by: Jeff Glatt 2007-06-27 15:40:26 (Total edited 2 times)
You use GuiAddCtlText().

You can add a new root parent node (at the end of the tree) with GuiAddCtlText(), by passing a third arg. But there isn't a way (right now) to add a new child to an existing parent, nor place a new root parent in a position other than the end.

The only way to do this is to reinitialize your stem variable describing the tree, and then call GuiAddCtlText().
/* Initialize items in the TREE */
mytreeitems.1 = 'Parent 1'
mytreeitems.2 = 'Parent 2'
mytreeitems.3 = 'Parent 3'

mytreeitems.3.1 = 'Child 1'
mytreeitems.3.2 = 'Child 2'

mytreeitems.3.2.1 = 'One more'

/* Do not select an item */
DROP mytree

guiaddctltext("MyTree", "MyTreeItems")

/* Add a child to Parent 2. NOTE: The other variables are
 * still set from above, and we don't need to change those.
mytreeitems.2.1 = 'Child 1'

guiaddctltext("MyTree", "MyTreeItems")
Posted by: mestrini 2007-06-27 16:45:18 Last edited by: Jeff Glatt 2007-07-03 08:37:41 (Total edited 3 times)
It's a shame that we can't add a child to a desired location in a tree. I could really use that feature; pls consider this a "REQ:"  ;)
Message4. Out of interest ...
Posted by: misi01 2007-06-28 18:47:05 Last edited by: Jeff Glatt 2007-07-03 08:39:24 (Total edited 2 times)
I looked over your original script. You use GuiImageList(). Where did you get that from?

Re, your comment about pushbutton 2, isn't the following what you're after instead ?
h=1; branch_check="dummy_value" /*looking for first available tree branch*/
   IF EXISTS('MyTreeItems.2.'||h) = 0 THEN LEAVE
Message5. THAT'S IT!
Posted by: mestrini 2007-06-28 19:43:15 Last edited by: Jeff Glatt 2007-07-03 08:33:37 (Total edited 2 times)
Thanks a lot michael! That did the trick.

The GuiImageList() is demonstrated in Jeff's TREE example script at his site.
Message6. deleted items appear again!
Posted by: mestrini 2007-06-28 20:23:11
Sorry to append this here but don't think this issue requires a dedicated thread.

Just add a PUSH button named 'del_button' to the test script above and append following code at the end
	guiremovectltext("MyTree", "") /*deleting selected branch*/
You'll see that after deleting items (any of your choice) and adding new ones it will make the original (and others added at runtime) appear again.
Message7. A thought ...
Posted by: Michael S 2007-06-28 23:08:15
without testing this, I had a problem that boiled down to the fact that Jeff said/suggested I DROP the variable containing the items I wanted to update (in my case, it was a listbox).

If you muck around with that (droppig the variable(s)), does it help ?
Message8. Re:A thought ...
Posted by: mestrini 2007-06-29 00:34:13 Last edited by: Jeff Glatt 2007-07-03 08:32:33 (Total edited 2 times)
It does work!! After some trial and error, I figured out how to have items not appear again.  It should be something like this:
    guiremovectltext("MyTree", "") /*deleting selected branch*/
    DROP mytree_items.mytree /*eliminating branch from the TREE 'pool'*/
Posted by: Jeff Glatt 2007-06-29 05:22:54
Yeah, if you're totally changing the configuration of the TREE, you should first DROP the variable to clear out the old definition. I didn't do that in my example because I was just adding another child to an existing configuration.
Posted by: Jeff Glatt 2007-06-29 13:53:12
Ok, in regards to that "crash". It actually wasn't crashing. It was simply causing the script to hang in the call to GuiGetMsg() (and never return). This is fixed in the latest REXX GUI.

The problem is that you were getting the NOVALUE condition raised inside of a REXX GUI event handler (that actually gets called within your own call GuiGetMsg). Because you weren't trapping NOVALUE any place in your script, this causes REXX GUI to close all your windows inside of GuiGetMsg, but unfortunately doesn't return. I've modified this so that it now does.

But of course, the initial problem is that you're using the VALUE function incorrectly. The first arg is the name of the variable. You're not quoting it, so what happens is you're trying to pass the value of that variable. It doesn't have a value so NOVALUE is raised. If you called VALUE with the first arg the way Mike does it with EXISTS, it would have worked.
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
© Sat 2022-10-1  Guidance Laboratory Inc. Hits:0