#include #include #include #include #include Global $idTreeview Global Const $TVM_SETITEM = $TV_FIRST + 13 Example() Func Example() GUICreate("My GUI with treeview", 320, 215) ; Local $idTreeview = GUICtrlCreateTreeView(6, 6, 200, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $idTreeview = GUICtrlCreateTreeView(5, 5, 310, 150, BitOR($TVS_CHECKBOXES, $TVS_FULLROWSELECT, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) Local $idA1 = GUICtrlCreateTreeViewItem("A1",$idTreeview) Local $idA2 = GUICtrlCreateTreeViewItem("A2",$idTreeview) Local $idA3 = GUICtrlCreateTreeViewItem("A3",$idTreeview) Local $idA4 = GUICtrlCreateTreeViewItem("A4",$idTreeview) Local $idB1 = GUICtrlCreateTreeViewItem("B1",$idTreeview) Local $idB2 = GUICtrlCreateTreeViewItem("B2",$idTreeview) Local $idB3 = GUICtrlCreateTreeViewItem("B3",$idTreeview) Local $idB4 = GUICtrlCreateTreeViewItem("B4",$idTreeview) Local $idButtonAll = GUICtrlCreateButton("All" , 5, 185, 35, 20) Local $idButtonCheckA = GUICtrlCreateButton("A only" , 40, 185, 60, 20) Local $idButtonCheckB = GUICtrlCreateButton("B only" ,100, 185, 60, 20) Local $idButtonViewAll = GUICtrlCreateButton("View All",160, 185, 60, 20) Local $idButtonViewSel = GUICtrlCreateButton("View Sel",220, 185, 60, 20) Local $idButtonClose = GUICtrlCreateButton("Close" ,280, 185, 35, 20) GUISetState(@SW_SHOW) Local $idMsg ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $idButtonClose Or $idMsg = $GUI_EVENT_CLOSE ExitLoop Case $idMsg = $idButtonAll ConsoleWrite("Button ALL" & @CRLF) _CheckThis($idA1) _CheckThis($idA2) _CheckThis($idA3) _CheckThis($idA4) _CheckThis($idB1) _CheckThis($idB2) _CheckThis($idB3) _CheckThis($idB4) Case $idMsg = $idButtonCheckA ConsoleWrite("Button A" & @CRLF) _CheckThis($idA1) _CheckThis($idA2) _CheckThis($idA3) _CheckThis($idA4) _UncheckThis($idB1) _UncheckThis($idB2) _UncheckThis($idB3) _UncheckThis($idB4) Case $idMsg = $idButtonCheckB ConsoleWrite("Button B" & @CRLF) _UncheckThis($idA1) _UncheckThis($idA2) _UncheckThis($idA3) _UncheckThis($idA4) _CheckThis($idB1) _CheckThis($idB2) _CheckThis($idB3) _CheckThis($idB4) Case $idMsg = $idButtonViewAll ConsoleWrite("View All" & @CRLF) Case $idMsg = $idButtonViewSel ConsoleWrite("View Sel => ") _ViewThis($idA1) _ViewThis($idA2) _ViewThis($idA3) _ViewThis($idA4) _ViewThis($idB1) _ViewThis($idB2) _ViewThis($idB3) _ViewThis($idB4) ConsoleWrite(@CRLF) EndSelect WEnd GUIDelete() EndFunc Func _ViewThis($handle) If BitAND(GUICtrlRead($handle),$GUI_CHECKED) Then ConsoleWrite("+") GUICtrlSetState($handle,$GUI_SHOW) GUICtrlSetState($handle,$GUI_CHECKED) Else ConsoleWrite("-") ; GUICtrlSetState($handle,$GUI_HIDE) ; GUICtrlSetState($handle,$GUI_DISABLE) RemoveCheckbox($idTreeview, $handle) EndIf EndFunc Func _CheckThis($handle) GUICtrlSetState($handle,$GUI_CHECKED) EndFunc Func _UncheckThis($handle) GUICtrlSetState($handle,$GUI_UNCHECKED) EndFunc ;https://www.autoitscript.com/forum/topic/118585-solved-disabling-parent-treeview-checkboxes/ ;Remove the square's checkbox but leave the text... Func RemoveCheckbox($nTV, $nID) Local $hItem = GUICtrlGetHandle($nID) If $hItem = 0 Then $hItem = $nID Local $stTVITEM = DllStructCreate('uint;uint;uint;uint;ptr;int;int;int;int;uint;int') DllStructSetData($stTVITEM, 1, $TVIF_STATE) DllStructSetData($stTVITEM, 2, $hItem) DllStructSetData($stTVITEM, 3, 0) DllStructSetData($stTVITEM, 4, $TVIS_STATEIMAGEMASK) GUICtrlSendMsg($nTV, $TVM_SETITEM, 0, DllStructGetPtr($stTVITEM)) EndFunc