Page 1 of 1

Feature TreeGadget items

Posted: Tue May 20, 2008 7:54 pm
by alban
Feature request for the value from AddGadgetItem to return the item value from a tree.

value = AddGadgetItem(#myTree, -1, Text$, 0, CurrentSublevel)

It would be nice if the value returned was the item number of the item just created.
Alternatively some other way of fetching the value of the last item created would be really useful.

Also a command like item=ParentItem( item) would be nice.
This would allow us to work our way back up a tree without using API calls.

Re: Feature TreeGadget items

Posted: Tue May 20, 2008 8:59 pm
by freak
alban wrote:Feature request for the value from AddGadgetItem to return the item value from a tree.

value = AddGadgetItem(#myTree, -1, Text$, 0, CurrentSublevel)

It would be nice if the value returned was the item number of the item just created.
Alternatively some other way of fetching the value of the last item created would be really useful.
If you pass -1 as position in the 2nd parameter, the new item will be at index CountGadgetItems(#myTree)-1,
and if you pass another position, the new item will be at the passed index.
alban wrote:Also a command like item=ParentItem( item) would be nice.
This would allow us to work our way back up a tree without using API calls.
Just examine the items sublevel like this:

Code: Select all

Procedure GetParent(tree, item)
  level  = GetGadgetItemAttribute(tree, item, #PB_Tree_Sublevel)
  parent = item-1
  While parent >= 0 And level <= GetGadgetItemAttribute(tree, parent, #PB_Tree_Sublevel)
    parent - 1
  Wend
  ProcedureReturn parent
EndProcedure
When walking the list backwards, the first item with a sublevel lower than the current one is always its parent.

Posted: Wed May 21, 2008 1:49 pm
by Trond
It would be nice if other List/Tree functions than AddGadgetItem() also accepted -1.