Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / Dynamically add a branch to a TREE

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Dynamically add a branch to a TREE
#10770
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?
Message2.
#10789
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")
Message3.
#10793
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 ...
#10830
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*/
DO FOREVER 
   IF EXISTS('MyTreeItems.2.'||h) = 0 THEN LEAVE
   h=h+1
END
Michael
Message5. THAT'S IT!
#10831
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!
#10832
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
wm_click_del_button:
	guigetctlvalue('MyTree')
	guiremovectltext("MyTree", "") /*deleting selected branch*/
RETURN
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 ...
#10833
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 ...
#10843
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:
wm_click_del_button:
    guigetctlvalue('MyTree')
    guiremovectltext("MyTree", "") /*deleting selected branch*/
    DROP mytree_items.mytree /*eliminating branch from the TREE 'pool'*/
RETURN
Message9.
#10852
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.
Message10.
#10859
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.
Email:webmaster1g.yi.org Hits:0