dazza Posted February 19, 2009 Share Posted February 19, 2009 I'm drowning. Treeviews are my nemesis, alongside beetroot. I have a Treeview with checked boxes. How do I loop through each node, checking whether each node is checked? <reaches for the Nurofen> Link to comment Share on other sites More sharing options...
Zedna Posted February 19, 2009 Share Posted February 19, 2009 My very old post but you can take it as start point :-)http://www.autoitscript.com/forum/index.php?showtopic=18409 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
dazza Posted February 19, 2009 Author Share Posted February 19, 2009 I manged to cobble this together, but the code stops after the first item in the treeview... I need to it work through all items in the treeview What am I doing wrong? expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> _Main() Func _Main() Local $hItem[10], $hTreeView Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES) GUICreate("TreeView Get Next", 400, 300) $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE) GUISetState() _GUICtrlTreeView_BeginUpdate($hTreeView) For $x = 0 To 3 $hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x + 1), $hTreeView) For $y = 1 To Random(2, 10, 1) GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $y), $hItem[$x]) Next Next $hItem[4] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", 5), $hTreeView) For $x = 5 To 9 $hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x + 1), $hTreeView) For $y = 1 To Random(2, 10, 1) GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $y), $hItem[$x]) Next Next _GUICtrlTreeView_EndUpdate($hTreeView) _GUICtrlTreeView_Expand($hTreeView) $h_itm = _GUICtrlTreeView_GetFirstItem($hTreeview) While 1 $text = _GUICtrlTreeView_GetText($hTreeview, $h_itm) If _GUICtrlTreeView_GetChecked($hTreeview, $h_itm) = true Then msgbox(0, $text, "is checked") Else msgbox(0, $text, "is NOT checked") EndIf $h_itm = _GUICtrlTreeView_GetNext($hTreeview, $h_itm) If $h_itm <= 0 then exitloop WEnd Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main Link to comment Share on other sites More sharing options...
Zedna Posted February 19, 2009 Share Posted February 19, 2009 Replace If $h_itm <= 0 then exitloop by If $h_itm = 0 then exitloop Also you mixed up control ID versus control handle. control ID is used in AutoIt's native functions and control handle is used in UDFs. You are lucky because many UDFs are written in way it correctly handles also control ID's instead of handles. But generally you shouldn't rely on this. expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> _Main() Func _Main() Local $hItem[10], $hTreeView Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES) GUICreate("TreeView Get Next", 400, 300) $idTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE) $hTreeView = GUICtrlGetHandle($idTreeView) GUISetState() _GUICtrlTreeView_BeginUpdate($hTreeView) For $x = 0 To 3 $hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x + 1), $idTreeView) For $y = 1 To Random(2, 10, 1) GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $y), $hItem[$x]) Next Next $hItem[4] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", 5), $idTreeView) For $x = 5 To 9 $hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x + 1), $idTreeView) For $y = 1 To Random(2, 10, 1) GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $y), $hItem[$x]) Next Next _GUICtrlTreeView_EndUpdate($hTreeView) _GUICtrlTreeView_Expand($hTreeView) $h_itm = _GUICtrlTreeView_GetFirstItem($hTreeview) While 1 $text = _GUICtrlTreeView_GetText($hTreeview, $h_itm) If _GUICtrlTreeView_GetChecked($hTreeview, $h_itm) = true Then ; msgbox(0, $text, "is checked") ConsoleWrite($text & " is checked" & @CRLF) Else ; msgbox(0, $text, "is NOT checked") ConsoleWrite($text & " is NOT checked" & @CRLF) EndIf $h_itm = _GUICtrlTreeView_GetNext($hTreeview, $h_itm) If $h_itm = 0 then exitloop WEnd Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
dazza Posted February 20, 2009 Author Share Posted February 20, 2009 Brilliant! Many thanks Zed! 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