AaronOoi Posted July 11, 2014 Share Posted July 11, 2014 (edited) Hi, I tried to capture an expanded Tree View item text from its child to it's parent. I already tried my best to make it with my limited logic knowledge When i clicked on OK button, the expected results should be Information Technology > AP > India > Workstations expandcollapse popup#NoTrayIcon #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Form1", 394, 300, 193, 124) $TreeView1 = GUICtrlCreateTreeView(8, 20, 369, 200) $TreeView1_83 = GUICtrlCreateTreeViewItem("Information Technology", $TreeView1) $TreeView1_84 = GUICtrlCreateTreeViewItem("AP", $TreeView1_83) $TreeView1_93 = GUICtrlCreateTreeViewItem("Malaysia", $TreeView1_84) $TreeView1_94 = GUICtrlCreateTreeViewItem("Workstations", $TreeView1_93) $TreeView1_95 = GUICtrlCreateTreeViewItem("Workstations-Test", $TreeView1_93) $TreeView1_96 = GUICtrlCreateTreeViewItem("Imaging-Workstations", $TreeView1_95) $TreeView1_97 = GUICtrlCreateTreeViewItem("India", $TreeView1_84) $TreeView1_98 = GUICtrlCreateTreeViewItem("Workstations", $TreeView1_97) $Button1 = GUICtrlCreateButton("Close", 288, 250, 81, 25) $Button2 = GUICtrlCreateButton("Ok", 192, 250, 81, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Exit Case $Button2 $idItem = GUICtrlRead($Treeview1) if StringInStr(GUICtrlRead($Treeview1,1),"workstation") = 0 then msgbox(16,$idItem,"Only workstations allowed to select.") Else msgbox(0,$idItem,GUICtrlRead($idItem-3,1)& " > " & GUICtrlRead($idItem-2,1)& " > " & GUICtrlRead($idItem-1,1)& " > " & GUICtrlRead($idItem,1)) EndIf EndSwitch WEnd Edited July 11, 2014 by AaronOoi Link to comment Share on other sites More sharing options...
Solution kylomas Posted July 11, 2014 Solution Share Posted July 11, 2014 AaronOoi, Here's one way to fo it... expandcollapse popup#NoTrayIcon #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> $Form1_1 = GUICreate("Form1", 394, 300, 193, 124) $TreeView1 = GUICtrlCreateTreeView(8, 20, 369, 200) $TreeView1_83 = GUICtrlCreateTreeViewItem("Information Technology", $TreeView1) $TreeView1_84 = GUICtrlCreateTreeViewItem("AP", $TreeView1_83) $TreeView1_93 = GUICtrlCreateTreeViewItem("Malaysia", $TreeView1_84) $TreeView1_94 = GUICtrlCreateTreeViewItem("Workstations", $TreeView1_93) $TreeView1_95 = GUICtrlCreateTreeViewItem("Workstations-Test", $TreeView1_93) $TreeView1_96 = GUICtrlCreateTreeViewItem("Imaging-Workstations", $TreeView1_95) $TreeView1_97 = GUICtrlCreateTreeViewItem("India", $TreeView1_84) $TreeView1_98 = GUICtrlCreateTreeViewItem("Workstations", $TreeView1_97) $Button1 = GUICtrlCreateButton("Close", 288, 250, 81, 25) $Button2 = GUICtrlCreateButton("Ok", 192, 250, 81, 25) GUISetState(@SW_SHOW) local $iCurrItem, $sOut = '' While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Exit Case $Button2 $idItem = GUICtrlRead($Treeview1) if StringInStr(GUICtrlRead($Treeview1,1),"workstation") = 0 then msgbox(16,$idItem,"Only workstations allowed to select.") Else $iCurrItem = _GUICtrlTreeView_GetSelection($TreeView1) while _guictrltreeview_getparenthandle($TreeView1,$iCurrItem) <> 0 $sOut = _guictrltreeview_gettext($TreeView1,$iCurrItem) & ' > ' & $sOut $iCurrItem = _guictrltreeview_getparenthandle($TreeView1,$iCurrItem) wend $sOut = _guictrltreeview_gettext($TreeView1,$iCurrItem) & ' > ' & $sOut $sOut = stringtrimright($sOut,3) ConsoleWrite($sOut & @CRLF) EndIf EndSwitch WEnd 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...
AaronOoi Posted July 11, 2014 Author Share Posted July 11, 2014 FUBAR, Amazing, this is exactly what I need, I could have not know that is the right way to do it like years!! Thank You Link to comment Share on other sites More sharing options...
kylomas Posted July 11, 2014 Share Posted July 11, 2014 Aaron, Forgot to reset var. Results are wrong when you click multiple workstations... expandcollapse popup#NoTrayIcon #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> $Form1_1 = GUICreate("Form1", 394, 300, 193, 124) $TreeView1 = GUICtrlCreateTreeView(8, 20, 369, 200) $TreeView1_83 = GUICtrlCreateTreeViewItem("Information Technology", $TreeView1) $TreeView1_84 = GUICtrlCreateTreeViewItem("AP", $TreeView1_83) $TreeView1_93 = GUICtrlCreateTreeViewItem("Malaysia", $TreeView1_84) $TreeView1_94 = GUICtrlCreateTreeViewItem("Workstations", $TreeView1_93) $TreeView1_95 = GUICtrlCreateTreeViewItem("Workstations-Test", $TreeView1_93) $TreeView1_96 = GUICtrlCreateTreeViewItem("Imaging-Workstations", $TreeView1_95) $TreeView1_97 = GUICtrlCreateTreeViewItem("India", $TreeView1_84) $TreeView1_98 = GUICtrlCreateTreeViewItem("Workstations", $TreeView1_97) $Button1 = GUICtrlCreateButton("Close", 288, 250, 81, 25) $Button2 = GUICtrlCreateButton("Ok", 192, 250, 81, 25) GUISetState(@SW_SHOW) local $iCurrItem, $sOut = '' While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Exit Case $Button2 $idItem = GUICtrlRead($Treeview1) if StringInStr(GUICtrlRead($Treeview1,1),"workstation") = 0 then msgbox(16,$idItem,"Only workstations allowed to select.") Else $iCurrItem = _GUICtrlTreeView_GetSelection($TreeView1) while _guictrltreeview_getparenthandle($TreeView1,$iCurrItem) <> 0 $sOut = _guictrltreeview_gettext($TreeView1,$iCurrItem) & ' > ' & $sOut $iCurrItem = _guictrltreeview_getparenthandle($TreeView1,$iCurrItem) wend $sOut = _guictrltreeview_gettext($TreeView1,$iCurrItem) & ' > ' & $sOut $sOut = stringtrimright($sOut,3) ConsoleWrite($sOut & @CRLF) $sOut = '' ; <<<<<------- forgot to blank out var for successive selections during single instance of script EndIf EndSwitch WEnd 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...
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