Congratulations. You have proved that You got the expected at expand/collapse event without any changing and I shame of me about persisting in something that you solved easily.Pablo César wrote:I am pretty sure what the user expect to be instead that
I was trying in this failed code:
Code: Select all
#include <hmg.ch>
FUNCTION Main()
PRIVATE aImageList := {}
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 286 ;
HEIGHT 460 ;
TITLE 'Tree Expand and Collapse Sample' ;
MAIN
DEFINE STATUSBAR FONT "Courier New" SIZE 10
STATUSITEM ""
END STATUSBAR
DEFINE TREE Tree_1 AT 10,10 WIDTH 260 HEIGHT 400 VALUE 3 ;
ON CHANGE OnChangeTree(This.TreeItemValue) ;
ON EXPAND OnExpandTree(This.TreeItemValue) ;
ON COLLAPSE OnCollapseTree(This.TreeItemValue) ;
NODEIMAGES { "NODE1_CL", "NODE1_OP" } ;
ITEMIMAGES { "PAGE_CL", "PAGE_OP" } ;
NOROOTBUTTON
//ITEMIDS
NODE 'Root' ; AADD(aImageList,0)
TREEITEM 'Item 1.1' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,0)
TREEITEM 'Item 1.2' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,0)
TREEITEM 'Item 1.3' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,0)
NODE 'Docs' IMAGES { "NODE1_CL", "NODE1_OP" } ; AADD(aImageList,2)
TREEITEM 'Docs 1' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,4)
TREEITEM 'Docs 2' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,4)
END NODE
NODE 'Folder' IMAGES { "NODE2_CL", "NODE2_OP" } ; AADD(aImageList,6)
TREEITEM 'Folder 1' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,8)
TREEITEM 'Folder 2' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,8)
END NODE
NODE 'Notes' IMAGES { "NODE3_CL", "NODE3_OP" } ; AADD(aImageList,10)
TREEITEM 'Notes 1' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,12)
TREEITEM 'Notes 2' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,12)
TREEITEM 'Notes 3' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,12)
TREEITEM 'Notes 4' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,12)
TREEITEM 'Notes 5' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,12)
END NODE
END NODE
END TREE
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
RETURN Nil
FUNCTION OnChangeTree(nItem)
Form_1.StatusBar.Item(1) := AllTrim(Str(nItem))+" - On Change - "+hb_ValToExp(Form_1.Tree_1.ImageIndex(nItem))
RETURN Nil
FUNCTION OnExpandTree(nItem)
LOCAL aImageList := Form_1.Tree_1.ImageIndex(nItem)
LOCAL nPos, aNewVal := {0,1}, lIsPair := IsPair(nItem)
nPos := AScan(aImageList,nItem)
If nPos>0
If lIsPair
aNewVal := {nItem,nItem+1}
Else
aNewVal := {nItem-1,nItem}
Endif
Endif
msgdebug(nPos,Form_1.Tree_1.ImageCount,aImageList,aImageList[nItem])
Form_1.StatusBar.Item(1) := AllTrim(Str(nItem))+" - On Expand - "+hb_ValToExp(Form_1.Tree_1.ImageIndex(nItem))
*Form_1.Tree_1.ImageIndex(nItem):={1,1}
Form_1.Tree_1.ImageIndex(nItem):=aNewVal
RETURN Nil
FUNCTION OnCollapseTree(nItem)
LOCAL aImageList := Form_1.Tree_1.ImageIndex(nItem)
LOCAL nPos, aNewVal := {0,1}, lIsPair := IsPair(nItem)
nPos := AScan(aImageList,nItem)
If nPos>0
If lIsPair
aNewVal := {nItem-1,nItem}
Else
aNewVal := {nItem,nItem-1}
Endif
Endif
msgdebug(nPos,Form_1.Tree_1.ImageCount,aImageList,aImageList[nItem])
Form_1.StatusBar.Item(1) := AllTrim(Str(nItem))+" - On Collapse - "+hb_ValToExp(Form_1.Tree_1.ImageIndex(nItem))
*Form_1.Tree_1.ImageIndex(nItem):={0,1}
Form_1.Tree_1.ImageIndex(nItem):=aNewVal
RETURN Nil
FUNCTION IsPair(nVal)
LOCAL lRet := .F.
If (nVal-Int(nVal))=0
lRet := .T.
Endif
RETURN lRet
It's your right to be in disagreed.edk wrote: ↑Fri Apr 28, 2017 7:23 pm Let me disagree with you.
Point me to where is the definition of tree object (+) / (-)? This is not a Node. Nodes are: 'Root', 'Docs', 'Folder', 'Notes'
(+) / (-) these are elements that have no definition, and as such values in Tree. So they are not part of a tree - in the sense that Expanded / Collapsed does not affect tree values.
They only serve to change the presentation of tree elements. And therefore they are handled separately from the rest of the tree.
I was wrong.
I noted these _HMG_This_TreeItem_Value := NIL at h_windows.prg and I thought tremendaly wrong. But it seems not.
Sorry to cause confusion and I thank you very much your valious patient.