Hello all,
For one year i seek on internet a method of checkall-uncheckall on a treeviewlist, i never found.
So finaly i decided to develop a function for that.
That code it is un complete example
For integrate at your treeview, you must copy Dim $checkverif[1][2], the 2 functions, the variable $declared. And call the functions CheckAll_UncheckALL_Declaration before the "while 1" and CheckAll_UncheckALL_Execution inside the "While 1"
CheckAll_UncheckALL_Declaration(treeview_name)
CheckAll_UncheckALL_Execution(treeview_name, array_declaration)
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
Dim $checkverif[1][2]
Func CheckAll_UncheckALL_Declaration($tree) ;Create variables of verification state
;---------------------------------------------------
$firstvisible = _GUICtrlTreeView_GetFirstVisible($tree) ;Get ID of the first visible element
$countverif = 0
if _GUICtrlTreeView_GetChildren($tree, $firstvisible) Then ;if the fisrt visible element has children
$checkverif[$countverif][0] = $firstvisible ;Get ID of fisrt visible element
$checkverif[$countverif][1] = False
$countverif = $countverif + 2
ReDim $checkverif[$countverif][2] ;Resize the array
$countverif = $countverif - 1 ;replacing the read array cursor
EndIf
;this part make the same things but for other parents
$getnext = _GUICtrlTreeView_GetNext($tree, $firstvisible)
While $getnext <> 0
if _GUICtrlTreeView_GetChildren($tree, $getnext) Then
$checkverif[$countverif][0] = $getnext
$checkverif[$countverif][1] = False
$countverif = $countverif + 2
ReDim $checkverif[$countverif][2]
$countverif = $countverif - 1
EndIf
$getnext = _GUICtrlTreeView_GetNext($tree, $getnext)
WEnd
_ArrayDelete($checkverif, $countverif) ;delete the last row because empty
Return $checkverif
EndFuncFunc CheckAll_UncheckALL_Execution($tree, $checkverif)
$countverif = UBound($checkverif)-1
For $i = 0 to $countverif Step 1
$state = _GUICtrlTreeView_GetChecked($tree, $checkverif[$i][0]) ;Get state of the parent
if $state <> $checkverif[$i][1] Then
$checkverif[$i][1] = _GUICtrlTreeView_GetChecked($tree, $checkverif[$i][0])
$firstchild = _GUICtrlTreeView_GetFirstChild($tree, $checkverif[$i][0]) ;Get ID of the first child
_GUICtrlTreeView_Expand($tree, $checkverif[$i][0]) ;Expand th parent
_GUICtrlTreeView_SetChecked($tree, $firstchild, $state) ;Check or unchek according to the texte
$child = _GUICtrlTreeView_GetNextSibling($tree, $firstchild) ;Get ID of next child
while _GUICtrlTreeView_GetNextSibling($tree, $child) <> 0 ;While nextsibling don't return 0
_GUICtrlTreeView_SetChecked($tree, $child, $state)
$child = _GUICtrlTreeView_GetNextSibling($tree, $child)
WEnd
_GUICtrlTreeView_SetChecked($tree, $child, $state) $checkverif[$i][1] = $state
EndIf
Next
$declared = $checkverif
Return $declared
EndFunc
Local $GUI, $hImage, $iImage, $hItem, $fDragging = False, $aDrag, $hTreeView
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES);~ Create dialog box
$GUI = GUICreate("TreeView Create Drage Image", 400, 300)
$hTreeView = GUICtrlGetHandle(GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE))
_GUICtrlTreeView_BeginUpdate($hTreeView)
For $x = 1 To Random(2, 10, 1)
$hItem = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x))
For $y = 1 To Random(2, 10, 1)
_GUICtrlTreeView_AddChild($hTreeView, $hItem, StringFormat("[%02d] New Child", $y))
Next
Next
_GUICtrlTreeView_EndUpdate($hTreeView)$declared = CheckAll_UncheckALL_Declaration($hTreeView) ;Call the function
GUISetState()
While 1
CheckAll_UncheckALL_Execution($hTreeView, $declared) ;Appel de la fonction
$msg = GUIGetMsg()
if $msg = $GUI_EVENT_CLOSE Then
ExitLoop
EndIf
WEnd