Jump to content

GUI tree checkboxes


 Share

Recommended Posts

Hello,
I need to make a GUI with checkboxes.
I made an example of how it should look. An example attached to the post.
How to make sure that when you check the Root item, child items are checked to?

And when checked with any of the child items, did the Root item also get checked?

The code does not have to see what it looks like. The main thing that would be convenient to add new items and make the GUI wiyh checkboxes.

Thank you!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <StringConstants.au3>

; The number of items will be added
Local $aItem_LIst1[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst2[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10", "Item 11"]
Local $aItem_LIst3[] = ["Item 1", "Item 2", "Item 3", "Item 4"]
Local $aItem_LIst4[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5" ,"Item 6"]
Local $aItem_LIst5[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"]
Local $aItem_LIst6[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst7[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst8[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst9[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst10[] = ["Item 1", "Item 2"]

Local $aPool[][] = [["Root item 1", $aItem_LIst1], _
                ["Root item 2", $aItem_LIst2], _
                ["Root item 3", $aItem_LIst3], _
                ["Root item 4", $aItem_LIst4], _
                ["Root item 5", $aItem_LIst5], _
                ["Root item 6", $aItem_LIst6], _
                ["Root item 7", $aItem_LIst7], _
                ["Root item 8", $aItem_LIst8], _
                ["Root item 9", $aItem_LIst9], _
                ["Root item 10", $aItem_LIst10]]


Local $hGUI = GuiCreate("Checkbox Tree", 240, 300, -1, -1)
Local $idButton = GUICtrlCreateButton("Action", 130, 250, 85, 25)
Local $idTreeView = GUICtrlCreateTreeView(16, 16, 200, 200, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES), $WS_EX_DLGMODALFRAME+$WS_EX_CLIENTEDGE)

#cs
The array created by this loop shows:
1 column - The name of the root item
2 column - root item ID
3 column - Name of child item
4 column - child item ID
5 column - Handle of a child item
6 column - Is child item is checked
#ce

Local $aItem_Controls[0][6]
For $i = 0 to UBound($aPool)-1
    $idRoot = GUICtrlCreateTreeViewItem($aPool[$i][0], $idTreeView)
    $aTemp = $aPool[$i][1]
    For $j = 0 to UBound($aTemp)-1
        $id_ChildItem = GUICtrlCreateTreeViewItem($aTemp[$j], $idRoot)
        $sList_Push = $aPool[$i][0]&"|"&$idRoot&"|"&$aTemp[$j]&"|"&$id_ChildItem&"|"&GUICtrlGetHandle($id_ChildItem)
        _ArrayAdd($aItem_Controls, $sList_Push)
    Next
Next

GUISetState(@SW_SHOW)
WinActivate($hGUI)

While 1
    $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $idButton; Mark a few items and click Action
                For $i = 0 to UBound($aItem_Controls) -1
                    $aItem_Controls[$i][5] = BitAND(GUICtrlRead($aItem_Controls[$i][3]), $GUI_CHECKED)
                Next
                _ArrayDisplay($aItem_Controls)
    EndSwitch
WEnd

 

Link to comment
Share on other sites

  • Moderators

Ipopraw,

Look at my GUITreeViewEx UDF (the link is in my sig) as this is exactly what it does.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

19 hours ago, Melba23 said:

Ipopraw,

Look at my GUITreeViewEx UDF (the link is in my sig) as this is exactly what it does.

M23

Thanks for the library! Works good.
What can I do next? I need the names of the checked items (Without root items).

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <StringConstants.au3>
#include "GUITreeViewEx.au3"

; The number of items will be added
Local $aItem_LIst1[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst2[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10", "Item 11"]
Local $aItem_LIst3[] = ["Item 1", "Item 2", "Item 3", "Item 4"]
Local $aItem_LIst4[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5" ,"Item 6"]
Local $aItem_LIst5[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"]
Local $aItem_LIst6[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst7[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst8[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst9[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst10[] = ["Item 1", "Item 2"]

Local $aPool[][] = [["Root item 1", $aItem_LIst1], _
                ["Root item 2", $aItem_LIst2], _
                ["Root item 3", $aItem_LIst3], _
                ["Root item 4", $aItem_LIst4], _
                ["Root item 5", $aItem_LIst5], _
                ["Root item 6", $aItem_LIst6], _
                ["Root item 7", $aItem_LIst7], _
                ["Root item 8", $aItem_LIst8], _
                ["Root item 9", $aItem_LIst9], _
                ["Root item 10", $aItem_LIst10]]

Local $hGUI = GuiCreate("Checkbox Tree", 240, 300, -1, -1)
Local $idButton = GUICtrlCreateButton("Action", 130, 250, 85, 25)
Local $idTreeView = GUICtrlCreateTreeView(16, 16, 200, 200, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES), $WS_EX_DLGMODALFRAME+$WS_EX_CLIENTEDGE)


Local $sTV_Data_1 = ""
For $i = 0 to UBound($aPool)-1
    $sTV_Data_1 &= $aPool[$i][0]&"|"
    $aTemp = $aPool[$i][1]
    For $j = 0 to Ubound($aTemp)-1
        $sTV_Data_1 &= "~"&$aTemp[$j]&"|"
    Next
Next

$sTV_Data_1 = StringTrimRight($sTV_Data_1, 1)

_GUITreeViewEx_LoadTV($idTreeView, $sTV_Data_1)

GUISetState(@SW_SHOW)
WinActivate($hGUI)

_GUITreeViewEx_InitTV($idTreeView)
_GUITreeViewEx_RegMsg()

While 1
    $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $idButton
                MsgBox($MB_SYSTEMMODAL, "Checked", _GUITreeViewEx_SaveTV($idTreeView, @CRLF))
        EndSwitch
    _GUITreeViewEx_AutoCheck()
WEnd

 

Edited by Ipopraw
Link to comment
Share on other sites

Done. It will suit me. My question can be considered closed.
If you have interesting ideas how else to solve this problem, continue the topic.

I can give an idea, output to the GUI how many checked items, like: 4/30 items checked.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <StringConstants.au3>
#include "GUITreeViewEx.au3"

; The number of items will be added
Local $aItem_LIst1[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst2[] = ["Item 21", "Item 22", "Item 23", "Item 24", "Item 25", "Item 26", "Item 27", "Item 28", "Item 29", "Item 210", "Item 211"]
Local $aItem_LIst3[] = ["Item 31", "Item 32", "Item 33", "Item 34"]
Local $aItem_LIst4[] = ["Item 41", "Item 42", "Item 43", "Item 44", "Item 45" ,"Item 46"]
Local $aItem_LIst5[] = ["Item 51", "Item 52", "Item 53", "Item 54", "Item 55", "Item 56", "Item 57", "Item 58", "Item 59", "Item 510"]
Local $aItem_LIst6[] = ["Item 61", "Item 62", "Item 63", "Item 64", "Item 65", "Item 66"]
Local $aItem_LIst7[] = ["Item 71", "Item 72", "Item 73", "Item 74", "Item 75", "Item 76"]
Local $aItem_LIst8[] = ["Item 81", "Item 82", "Item 83", "Item 84", "Item 85", "Item 86"]
Local $aItem_LIst9[] = ["Item 91", "Item 92", "Item 93", "Item 94", "Item 95", "Item 96"]
Local $aItem_LIst10[] = ["Item 101", "Item 102"]

Local $aPool[][] = [["Root item 1", $aItem_LIst1], _
                ["Root item 2", $aItem_LIst2], _
                ["Root item 3", $aItem_LIst3], _
                ["Root item 4", $aItem_LIst4], _
                ["Root item 5", $aItem_LIst5], _
                ["Root item 6", $aItem_LIst6], _
                ["Root item 7", $aItem_LIst7], _
                ["Root item 8", $aItem_LIst8], _
                ["Root item 9", $aItem_LIst9], _
                ["Root item 10", $aItem_LIst10]]

Local $hGUI = GuiCreate("Checkbox Tree", 240, 300, -1, -1)
Local $idButton = GUICtrlCreateButton("Action", 130, 250, 85, 25)
Local $idTreeView = GUICtrlCreateTreeView(16, 16, 200, 200, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES), $WS_EX_DLGMODALFRAME+$WS_EX_CLIENTEDGE)


Local $sTV_Data_1 = ""
For $i = 0 to UBound($aPool)-1
    $sTV_Data_1 &= $aPool[$i][0]&"|"
    $aTemp = $aPool[$i][1]
    For $j = 0 to Ubound($aTemp)-1
        $sTV_Data_1 &= "~"&$aTemp[$j]&"|"
    Next
Next
$sTV_Data_1 = StringTrimRight($sTV_Data_1, 1)

_GUITreeViewEx_LoadTV($idTreeView, $sTV_Data_1)

GUISetState(@SW_SHOW)
WinActivate($hGUI)

_GUITreeViewEx_InitTV($idTreeView)
_GUITreeViewEx_RegMsg()

While 1
    $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $idButton
                Get_Items()
        EndSwitch
    _GUITreeViewEx_AutoCheck()
WEnd

Func Get_Items()
    $aChecked = StringSplit(_GUITreeViewEx_SaveTV($idTreeView, @CR), @CR)

    Local $sDeleteRows = ""
    For $i = 1 To Ubound($aChecked)-1
        $sTempStr = StringRegExp($aChecked[$i], "#", $STR_REGEXPMATCH)
        If Not $sTempStr Then
            $sDeleteRows &= $i & ";"
        EndIf
    Next
    $sDeleteRows = StringTrimRight($sDeleteRows, 1) ;Remove last ";".
    _ArrayDelete($aChecked, $sDeleteRows)

    Local $sDeleteRows = ""
    For $i = 1 To Ubound($aChecked)-1
        $sTempStr = StringRegExp($aChecked[$i], "~", $STR_REGEXPMATCH)
        If Not $sTempStr Then
            $sDeleteRows &= $i & ";"
        EndIf
    Next
    $sDeleteRows = StringTrimRight($sDeleteRows, 1) ;Remove last ";".
    _ArrayDelete($aChecked, $sDeleteRows)

    For $i = 1 to Ubound($aChecked)-1
        $aChecked[$i] = StringTrimLeft($aChecked[$i], 2)
    Next

    _ArrayDelete($aChecked, 0)
    _ArrayDisplay($aChecked)
EndFunc

 

Link to comment
Share on other sites

I was trying to find a way to do it with the original code, but i may have stumped into a bug.

So this code checks all child items, but also the first parent in the list.

It's related to the zero-based check, and i don't know how to solve it.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <StringConstants.au3>

; The number of items will be added
Local $aItem_LIst1[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst2[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10", "Item 11"]
Local $aItem_LIst3[] = ["Item 1", "Item 2", "Item 3", "Item 4"]
Local $aItem_LIst4[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5" ,"Item 6"]
Local $aItem_LIst5[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"]
Local $aItem_LIst6[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst7[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst8[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst9[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
Local $aItem_LIst10[] = ["Item 1", "Item 2"]

Local $aPool[][] = [["Root item 1", $aItem_LIst1], _
                ["Root item 2", $aItem_LIst2], _
                ["Root item 3", $aItem_LIst3], _
                ["Root item 4", $aItem_LIst4], _
                ["Root item 5", $aItem_LIst5], _
                ["Root item 6", $aItem_LIst6], _
                ["Root item 7", $aItem_LIst7], _
                ["Root item 8", $aItem_LIst8], _
                ["Root item 9", $aItem_LIst9], _
                ["Root item 10", $aItem_LIst10]]


Local $hGUI = GuiCreate("Checkbox Tree", 240, 500, -1, -1)
Local $idButton = GUICtrlCreateButton("Action", 130, 450, 85, 25)
Local $idTreeView = GUICtrlCreateTreeView(16, 16, 200, 400, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES), $WS_EX_DLGMODALFRAME+$WS_EX_CLIENTEDGE)
Local $ItemState, $ItemHdl, $Count

Local $aItem_Controls[0][6]
For $i = 0 to UBound($aPool)-1
    $idRoot = GUICtrlCreateTreeViewItem($aPool[$i][0], $idTreeView)
    $aTemp = $aPool[$i][1]
    For $j = 0 to UBound($aTemp)-1
        $id_ChildItem = GUICtrlCreateTreeViewItem($aTemp[$j], $idRoot)
        $sList_Push = $aPool[$i][0]&"|"&$idRoot&"|"&$aTemp[$j]&"|"&$id_ChildItem&"|"&GUICtrlGetHandle($id_ChildItem)
        _ArrayAdd($aItem_Controls, $sList_Push)
    Next
Next

GUISetState(@SW_SHOW)
WinActivate($hGUI)

While 1
    $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
;=============================================================================
$ItemHdl = _GUICtrlTreeView_GetSelection($idTreeView)
$ItemState = _GUICtrlTreeView_GetState($idTreeView, $ItemHdl)
ConsoleWrite($ItemHdl&' - '&$ItemState &@CRLF)
If $ItemState = '8290' Or $ItemState = '8194' Then
_GUICtrlTreeView_Expand($idTreeView, $ItemHdl, True)
ConsoleWrite($ItemState&' - '&$ItemHdl &@CRLF)
$Count = _GUICtrlTreeView_GetChildCount($idTreeView, $ItemHdl)
For $c = 0 To $Count
    _GUICtrlTreeView_SetCheckedByIndex($idTreeView, $ItemHdl, $c, True)
Next
_GUICtrlTreeView_SetChecked($idTreeView, $ItemHdl, False)
EndIf
Sleep(100)
WEnd

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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...