behdadsoft Posted May 14, 2015 Share Posted May 14, 2015 Hi.I wrote below code that create tree with items and child.now I want when (only each child) is selected, show me child number with msgbox(). I searched in forum and find somethings but really I'm confused. if possible please guide me.Thanks.#RequireAdmin #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;global variables global $aStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) global $GUI global $treeObj global $treeItem global $treeChild ;Create and show GUI $GUI = GUICreate("TreeView Add", 400, 300) GUISetState(@SW_SHOW,$GUI) ;Create Tree Object $treeObj = GUICtrlCreateTreeView(2, 2, 300, 268,$aStyle,$WS_EX_CLIENTEDGE) ;Add Item and Child to Tree Object for $i = 1 to 4 $treeItem = GUICtrlCreateTreeViewItem ( "Item" & " " & $i , $treeObj ) for $j = 1 to 4 $treeChild = GUICtrlCreateTreeViewItem ( "Child" & " " & $j , $treeItem ) next Next ;loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($GUI) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 14, 2015 Moderators Share Posted May 14, 2015 behdadsoft,Try looking through the GuiTreeView UDF - there are a coupe of functions in there that will help you determine which item is selected and how to get its text.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MikahS Posted May 14, 2015 Share Posted May 14, 2015 (edited) A couple things to begin with. Not using an array in your For..Next loops to hold Ctrl Ids makes it so $treeItem and $treeChild will only hold the last item. Here is an example using Dummy Ctrls, with the changes to the For..Next loop:expandcollapse popup#RequireAdmin #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;global variables global $aStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) global $GUI global $treeObj global $treeItem[5] global $treeChild[5] ;Create and show GUI $GUI = GUICreate("TreeView Add", 400, 300) GUISetState(@SW_SHOW,$GUI) ;Create Tree Object $treeObj = GUICtrlCreateTreeView(2, 2, 300, 268,$aStyle,$WS_EX_CLIENTEDGE) ;Add Item and Child to Tree Object Local $iStart = GUICtrlCreateDummy() for $i = 1 to 4 ; start off in first element of array $treeItem[$i] = GUICtrlCreateTreeViewItem ( "Item" & " " & $i , $treeObj ) for $j = 1 to 4 ; start off in first element of array $treeChild[$j] = GUICtrlCreateTreeViewItem ( "Child" & " " & $j , $treeItem[$i] ) next Next Local $iEnd = GUICtrlCreateDummy() ;loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iStart To $iEnd MsgBox(0, "", GUICtrlRead($treeObj, 1)) EndSwitch WEnd GUIDelete($GUI)Any use? Edited May 14, 2015 by MikahS syntax Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
bernd670 Posted May 14, 2015 Share Posted May 14, 2015 Hello,try it with _GUICtrlTreeView_GetSelection, _GUICtrlTreeView_GetText and _GUICtrlTreeView_GetParentHandleexpandcollapse popup#RequireAdmin #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;global variables Global $aStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) Global $GUI Global $treeObj Global $treeItem Global $treeChild ;Create and show GUI $GUI = GUICreate("TreeView Add", 400, 300) GUISetState(@SW_SHOW, $GUI) ;Create Tree Object $treeObj = GUICtrlCreateTreeView(2, 2, 300, 268, $aStyle, $WS_EX_CLIENTEDGE) ;Add Item and Child to Tree Object For $i = 1 To 4 $treeItem = GUICtrlCreateTreeViewItem("Item" & " " & $i, $treeObj) For $j = 1 To 4 $treeChild = GUICtrlCreateTreeViewItem("Child" & " " & $j, $treeItem) Next Next $iLastSel = 0 ;loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch If $iLastSel <> _GUICtrlTreeView_GetSelection($treeObj) Then $iLastSel = _GUICtrlTreeView_GetSelection($treeObj) ConsoleWrite("Parent: " & _GUICtrlTreeView_GetText($treeObj, _GUICtrlTreeView_GetParentHandle($treeObj, $iLastSel)) & @CRLF) ConsoleWrite("Selected: " & _GUICtrlTreeView_GetText($treeObj, $iLastSel) & @CRLF) EndIf WEnd GUIDelete($GUI) greetingsbernd I hacked 127.0.0.1 -> Link to comment Share on other sites More sharing options...
behdadsoft Posted May 14, 2015 Author Share Posted May 14, 2015 Thanks all for help.@MikahScan you Explanation more about GUICtrlCreateDummy()?and I want msgbox only show for child and no items. Link to comment Share on other sites More sharing options...
MikahS Posted May 14, 2015 Share Posted May 14, 2015 (edited) @behdadsoft a simple explanation: https://www.autoitscript.com/forum/topic/141263-can-someone-explain-gui-dummy-controls-to-me/?do=findComment&comment=993463This will only bring up the message box for the child not items:expandcollapse popup#RequireAdmin #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;global variables Global $aStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) Global $GUI Global $treeObj Global $treeItem[5] Global $treeChild[5] Local $treeText ;Create and show GUI $GUI = GUICreate("TreeView Add", 400, 300) GUISetState(@SW_SHOW, $GUI) ;Create Tree Object $treeObj = GUICtrlCreateTreeView(2, 2, 300, 268, $aStyle, $WS_EX_CLIENTEDGE) ;Add Item and Child to Tree Object Local $iStart = GUICtrlCreateDummy() For $i = 1 To 4 ; start off in first element of array $treeItem[$i] = GUICtrlCreateTreeViewItem("Item" & " " & $i, $treeObj) For $j = 1 To 4 ; start off in first element of array $treeChild[$j] = GUICtrlCreateTreeViewItem("Child" & " " & $j, $treeItem[$i]) Next Next Local $iEnd = GUICtrlCreateDummy() ;loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iStart To $iEnd $treeText = GUICtrlRead($treeObj, 1) If Not StringInStr($treeText, "Item") Then MsgBox(0, "", $treeText) EndIf EndSwitch WEnd GUIDelete($GUI)All good? Edited May 14, 2015 by MikahS spelling behdadsoft 1 Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
behdadsoft Posted May 14, 2015 Author Share Posted May 14, 2015 thanks MikahS+1 Link to comment Share on other sites More sharing options...
MikahS Posted May 14, 2015 Share Posted May 14, 2015 My pleasure @behdadsoft. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
behdadsoft Posted May 14, 2015 Author Share Posted May 14, 2015 @MikahSI want instead of "Item" in StringInStr($treeText, "Item") use below code for automaticaly check name. but problem is StringInStr work Vice versa.please guide me to fix it.;loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iStart To $iEnd $treeText = GUICtrlRead($treeObj, 1) for $c = 1 to UBound($treeItem)-1 If Not StringInStr($treeText,$treeItem[$c],0) Then MsgBox(0, "", GUICtrlRead($treeObj, 1)) EndIf next EndSwitch WEndThanks. Link to comment Share on other sites More sharing options...
MikahS Posted May 18, 2015 Share Posted May 18, 2015 My apologies @behdadsoft I did not see this reply, still working out the kinks in the new forum for notifications. Here is an example as you described, that matches the selected and checks it against the child treeview items:expandcollapse popup#RequireAdmin #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;global variables Global $aStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) Global $GUI Global $treeObj Global $treeItem[5] Global $treeChild[5] Local $treeText ;Create and show GUI $GUI = GUICreate("TreeView Add", 400, 300) GUISetState(@SW_SHOW, $GUI) ;~ GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;Create Tree Object $treeObj = GUICtrlCreateTreeView(2, 2, 300, 268, $aStyle, $WS_EX_CLIENTEDGE) ;Add Item and Child to Tree Object Local $iStart = GUICtrlCreateDummy() For $i = 1 To 4 ; start off in first element of array $treeItem[$i] = GUICtrlCreateTreeViewItem("Item" & " " & $i, $treeObj) For $j = 1 To 4 ; start off in first element of array $treeChild[$j] = GUICtrlCreateTreeViewItem("Child" & " " & $j, $treeItem[$i]) Next Next Local $iEnd = GUICtrlCreateDummy() ;loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iStart To $iEnd $treeText = GUICtrlRead($treeObj, 1) For $q = 1 to UBound($treeChild) -1 If $treeText = GUICtrlRead($treeChild[$q], 1) Then MsgBox(0, "", $treeText) ExitLoop EndIf next EndSwitch WEnd GUIDelete($GUI)All good? Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ 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