ShikiPiki Posted September 12, 2013 Share Posted September 12, 2013 (edited) So, I've been creating a treeview using the GUICtrlCreateTreeView help file and so far what I have is a tree view with item 1 sub item 1- 5 item 2 sub item 1-5 Next to the tree is a list, and the user can add items from the tree. All of these functions work as intended however now what I'm trying to do with the items added is the following: When I select item 1/ subitem 3 and press the add button. not only do i want it to add it to the list but i want to get its indices. So as a return i would want something like [1,3] and save it to an array. I've been snooping around for a function to get these indices and I’ve come across a topic which speaks of developing something like it.. But i can't seem to find any complete functions. Is there one for it? The reason why I want the indices is because when i populate my tree list i take it from a 10 by 5 array and use the first 2 columns, the first being the item number and the 2nd being the item name. Item 3,4 and 5 are all properties which I will use to make calculations but I don't want the user to see these properties because it would not be neat. So, once I add the items I need their indices so i can go back to the proper location in the original array and find what properties the item they added have and do calculations. Maybe there is a more simple way to do this which is why I wished to explain in full detail my objective. Thank you. -Shikipiki Edit1 : Fixed some grammar and spelling mistakes to be more clear. Sorry If I am unclear. Edited September 12, 2013 by ShikiPiki Thanks! -ShikiPiki Link to comment Share on other sites More sharing options...
MilesAhead Posted September 12, 2013 Share Posted September 12, 2013 Not sure if this is it but it looks close '?do=embed' frameborder='0' data-embedContent>> My Freeware Page Link to comment Share on other sites More sharing options...
ShikiPiki Posted September 13, 2013 Author Share Posted September 13, 2013 Not sure if this is it but it looks close '?do=embed' frameborder='0' data-embedContent>> I saw this as well, and although it would give me the index of the subitems I would like their full path so when i look at item 1 sub item 3 i dont just get 3, i get [1,3]. Thanks! -ShikiPiki Link to comment Share on other sites More sharing options...
kylomas Posted September 13, 2013 Share Posted September 13, 2013 (edited) ShikiPiki, One way to get the parent / child (assumes only two levels for tree control... expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #AutoIt3Wrapper_Add_Constants=n local $gui010 = guicreate('TreeView Example',400,600) local $hTV = guictrlcreatetreeview(20,20,300,500) local $btn010 = guictrlcreatebutton('Press Me!',20,550,360,20) ; populate treeview local $hItem for $1 = 0 to 9 $hItem = _guictrltreeview_add($hTV,0,'Item - ' & stringformat('%03i',$1)) for $2 = 0 to random(1,10,1) _GUICtrlTreeView_AddChild($hTV,$hItem,'Child - ' & stringformat('%03i',$2)) Next Next guisetstate() while 1 switch guigetmsg() case $gui_event_close Exit case $btn010 _show_tree() endswitch wend func _show_tree() local $hSel, $hParent $hSel = _guictrltreeview_getselection($hTV) $hParent = _GUICtrlTreeView_GetParentHandle($hTV,$hSel) if $hParent <> 0 then _ ConsoleWrite(_GUICtrlTreeView_GetText($hTV,$hParent) & '\' & _GUICtrlTreeView_GetText($hTV,$hSel) & @LF) endfunc kylomas edit: changed code to not output console message if top level selection Edited September 13, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Solution kylomas Posted September 13, 2013 Solution Share Posted September 13, 2013 ShikiPiki, This one is more flexible. It will return the parent tree from the selected item anywhere in the tree... expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #AutoIt3Wrapper_Add_Constants=n local $gui010 = guicreate('TreeView Example',400,600) local $hTV = guictrlcreatetreeview(20,20,300,500) local $btn010 = guictrlcreatebutton('Press Me!',20,550,360,20) ; populate treeview local $hItem for $1 = 0 to 9 $hItem = _guictrltreeview_add($hTV,0,'Item - ' & stringformat('%03i',$1)) for $2 = 0 to random(1,10,1) $hChild = _GUICtrlTreeView_AddChild($hTV,$hItem,'Child - ' & stringformat('%03i',$2)) for $3 = 0 to random(1,5,1) $hSubChild = _guictrltreeview_addchild($hTV,$hChild,'Sub-Child - ' & stringformat('%03i',$3)) for $4 = 0 to random(1,5,1) _guictrltreeview_addchild($hTV,$hSubChild,'Sub-Sub-Child - ' & stringformat('%03i',$4)) next next Next Next guisetstate() while 1 switch guigetmsg() case $gui_event_close Exit case $btn010 consolewrite(_show_tree() & @lf) endswitch wend func _show_tree() local $hSel, $hParent, $sTree = '', $idx = 0 $hSel = _guictrltreeview_getselection($hTV) $hParent = _GUICtrlTreeView_GetParentHandle($hTV,$hSel) $sTree &= _GUICtrlTreeView_GetText($hTV,$hSel) & ',' $sTree &= _GUICtrlTreeView_GetText($hTV,$hParent) & ',' while 1 $hSel = $hParent $hParent = _GUICtrlTreeView_GetParentHandle($hTV,$hSel) if $hParent = 0 then exitloop $sTree &= _GUICtrlTreeView_GetText($hTV,$hParent) & ',' wend local $aTMP = stringsplit(stringtrimright($sTree,1),',',2) $sTree = '' for $1 = ubound($aTMP) -1 to 0 step -1 $sTree &= $aTMP[$1] & ' \ ' Next return stringtrimright($sTree,3) endfunc kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
ShikiPiki Posted September 13, 2013 Author Share Posted September 13, 2013 Ohhh, interesting! Thank you! Thanks! -ShikiPiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now