Jump to content

CheckAll-UncheckAll function


Redemption
 Share

Recommended Posts

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
Link to comment
Share on other sites

Hello Redemption,

fine script and thnaks for sharing! It will be usefull on some codes I`m working with.

However I have found some little errors on that I have corrected.

So in the following the fully functional script.

Cheers,

Kebarb

#include
#include
#include
#include

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
EndFunc
Func 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
Link to comment
Share on other sites

The Forum has lost the include files and does anyone use Tidy.exe? Or is it the Forum too?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

does anyone use Tidy.exe? Or is it the Forum too?

Forum. On edit it breaks some formatting =(

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Well I don't think they use Tidy or proper indentation as If is if in the examples above.

To overcome this is pretty easy, just toggle the editing mode to plain (basic) text and voila it works. The button is located next to 'Remove Format' and 'Special BBCode.'

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Hello Redemption,

fine script and thnaks for sharing! It will be usefull on some codes I`m working with.

However I have found some little errors on that I have corrected.

So in the following the fully functional script.

Cheers,

Kebarb

#include
#include
#include
#include

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
EndFunc
Func 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

Hello, thank you for reply,

i saw your code and i don't find your correction.

Give me the ligne please :bye:

Edited by Redemption
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...