Jump to content

Select Checkboxes and Copy


DigDeep
 Share

Recommended Posts

Hi,

I need some help here. My below code works fine except for few options.

1. When I select the check boxes, I want the text written in selected Checkboxes be copied. I tried few options but Copy button does not copies the selected Checkboxes.

2. I also need 2 more buttons for Expand all and Collaps all.

3. When I open this code, the treeview displays from the extreme top of the screen. I want to add some lines as space for better view. But as I created these are Treeview rather than CheckBox views I am not able to get them adjusted.

Can someone please help me here.

 

; Create flag to indicate item selection change
Global $ItemSelected = False
; Create array to hold item data
Global $TreeMenu[17][3]

; Create GUI
Global $CT = GUICreate("CT", 1896, 984, 3, 2, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))

; Create TreeView
Global $Check = GUICtrlCreateTreeView(10, 10, 600, 900, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES, $TVS_HASLINES, $TVS_NONEVENHEIGHT))

;$Label1 = GUICtrlCreateLabel("SCCM Scenarios", 472, 16, 45, 20)
; Fill TreeView
$TreeMenu[0][2]  = GUICtrlCreateTreeViewItem("  Option 1", $Check)
$TreeMenu[1][2]  = GUICtrlCreateTreeViewItem("  True", $TreeMenu[0][2])
$TreeMenu[2][2]  = GUICtrlCreateTreeViewItem("  ABC", $TreeMenu[1][2])
$TreeMenu[3][2]  = GUICtrlCreateTreeViewItem("  False", $TreeMenu[0][2])
$TreeMenu[4][2]  = GUICtrlCreateTreeViewItem("  DEF", $TreeMenu[3][2])
$TreeMenu[5][2]  = GUICtrlCreateTreeViewItem("  GHI", $TreeMenu[4][2])
$TreeMenu[6][2]  = GUICtrlCreateTreeViewItem("  MayBe", $TreeMenu[0][2])
$TreeMenu[7][2]  = GUICtrlCreateTreeViewItem("  JKL", $TreeMenu[6][2])

$TreeMenu[7][2]  = GUICtrlCreateTreeViewItem("  Option 2", $Check)
$TreeMenu[8][2]  = GUICtrlCreateTreeViewItem("  True", $TreeMenu[7][2])
$TreeMenu[9][2]  = GUICtrlCreateTreeViewItem("  MNO", $TreeMenu[8][2])
$TreeMenu[10][2]  = GUICtrlCreateTreeViewItem("  False", $TreeMenu[7][2])
$TreeMenu[11][2]  = GUICtrlCreateTreeViewItem("  PQR", $TreeMenu[10][2])
$TreeMenu[12][2]  = GUICtrlCreateTreeViewItem("  STU", $TreeMenu[11][2])



; Set initial unchecked state and get item handles (needed for later code)
For $i = 0 To UBound($TreeMenu) - 1
    $TreeMenu[$i][1] = False
    $TreeMenu[$i][0] = GUICtrlGetHandle($TreeMenu[$i][2])
Next

; Expand TreeView
;_GUICtrlTreeView_Expand($Check)

; Create buttons to set/clear all items
Global $Select_All = GUICtrlCreateButton("Select All", 20, 930, 144, 30)
Global $Clear_All = GUICtrlCreateButton("Clear All", 188, 930, 152, 30)
Global $Copy = GUICtrlCreateButton("Submit", 448, 928, 147, 33)

GUISetState()

; Register message to look for TV item selection change
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
#EndRegion ### END Koda GUI section ###

Global $bState, $iItemIndex, $sChkValues
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Select_All
            _Adjust_All()
        Case $Clear_All
            _Adjust_All(False)

        Case $Copy
        ; Copy to Clipboard




    EndSwitch

 

Edited by DigDeep
Link to comment
Share on other sites

Please post a runable script:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\Bert\AutoIt3.My\Test\treviewCheckBoxes.au3" /UserParams    
+>17:50:31 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000407  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0407)
+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE 
+>Check for missing standard constants/udf include files: 3 include(s) were added
>Running AU3Check (3.3.14.1)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Test\treviewCheckBoxes.au3
"C:\Users\Bert\AutoIt3.My\Test\treviewCheckBoxes.au3"(77,5) : error: missing Wend.
    EndSwitch
~~~~^
"C:\Users\Bert\AutoIt3.My\Test\treviewCheckBoxes.au3"(61,1) : REF: missing Wend.
While
^
"C:\Users\Bert\AutoIt3.My\Test\treviewCheckBoxes.au3"(57,40) : error: _WM_NOTIFY(): undefined function.
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Test\treviewCheckBoxes.au3"(67,25) : error: _Adjust_All(): undefined function.
            _Adjust_All()
~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Test\treviewCheckBoxes.au3 - 3 error(s), 0 warning(s)
!>17:50:33 AU3Check ended. Press F4 to jump to next error.rc:2
+>17:50:34 AutoIt3Wrapper Finished.
>Exit code: 2    Time: 2.894

and i added 3 includes before these errors: #include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>

Link to comment
Share on other sites

Here's the code...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <Array.au3>

#Region ### START Koda GUI section ### Form=

; Create flag to indicate item selection change
Global $ItemSelected = False
; Create array to hold item data
Global $TreeMenu[17][3]

; Create GUI
Global $CT = GUICreate("CT", 1896, 984, 3, 2, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))

; Create TreeView
Global $Check = GUICtrlCreateTreeView(10, 10, 600, 900, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES, $TVS_HASLINES, $TVS_NONEVENHEIGHT))

;$Label1 = GUICtrlCreateLabel("SCCM Scenarios", 472, 16, 45, 20)
; Fill TreeView
$TreeMenu[0][2]  = GUICtrlCreateTreeViewItem("  Option 1", $Check)
$TreeMenu[1][2]  = GUICtrlCreateTreeViewItem("  True", $TreeMenu[0][2])
$TreeMenu[2][2]  = GUICtrlCreateTreeViewItem("  ABC", $TreeMenu[1][2])
$TreeMenu[3][2]  = GUICtrlCreateTreeViewItem("  False", $TreeMenu[0][2])
$TreeMenu[4][2]  = GUICtrlCreateTreeViewItem("  DEF", $TreeMenu[3][2])
$TreeMenu[5][2]  = GUICtrlCreateTreeViewItem("  GHI", $TreeMenu[4][2])
$TreeMenu[6][2]  = GUICtrlCreateTreeViewItem("  MayBe", $TreeMenu[0][2])
$TreeMenu[7][2]  = GUICtrlCreateTreeViewItem("  JKL", $TreeMenu[6][2])

$TreeMenu[7][2]  = GUICtrlCreateTreeViewItem("  Option 2", $Check)
$TreeMenu[8][2]  = GUICtrlCreateTreeViewItem("  True", $TreeMenu[7][2])
$TreeMenu[9][2]  = GUICtrlCreateTreeViewItem("  MNO", $TreeMenu[8][2])
$TreeMenu[10][2]  = GUICtrlCreateTreeViewItem("  False", $TreeMenu[7][2])
$TreeMenu[11][2]  = GUICtrlCreateTreeViewItem("  PQR", $TreeMenu[10][2])
$TreeMenu[12][2]  = GUICtrlCreateTreeViewItem("  STU", $TreeMenu[11][2])


; Set initial unchecked state and get item handles (needed for later code)
For $i = 0 To UBound($TreeMenu) - 1
    $TreeMenu[$i][1] = False
    $TreeMenu[$i][0] = GUICtrlGetHandle($TreeMenu[$i][2])
Next

; Expand TreeView
;_GUICtrlTreeView_Expand($Check)

; Create buttons to set/clear all items
Global $Select_All = GUICtrlCreateButton("Select All", 20, 930, 144, 30)
Global $Clear_All = GUICtrlCreateButton("Clear All", 188, 930, 152, 30)
Global $Copy = GUICtrlCreateButton("Submit", 448, 928, 147, 33)

GUISetState()

; Register message to look for TV item selection change
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
#EndRegion ### END Koda GUI section ###

Global $bState, $iItemIndex, $sChkValues
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Select_All
            _Adjust_All()
        Case $Clear_All
            _Adjust_All(False)

        Case $Copy
        ; Copy to Clipboard


    EndSwitch

    ; An item has been selected
    If $ItemSelected Then
        ; Determine checked state
        $bState = _GUICtrlTreeView_GetChecked($Check, $ItemSelected)
        ; Find item in array
        $iItemIndex = _ArraySearch($TreeMenu, $ItemSelected)
        ; If checked state has altered
        If $TreeMenu[$iItemIndex][1] <> $bState Then
            ; Store new state
            $TreeMenu[$iItemIndex][1] = $bState
            ; Adjust parents and children as required
            _Adjust_Parents($ItemSelected, $bState)
            _Adjust_Children($ItemSelected, $bState)
        EndIf
        ; Clear flag
        $ItemSelected = 0
    EndIf

WEnd

Func _Adjust_All($bState = True)

    ; Loop through items
    For $i = 0 To UBound($TreeMenu) - 1
        ; Adjust item
        _GUICtrlTreeView_SetChecked($Check, $TreeMenu[$i][0], $bState)
        ; Adjust array
        $TreeMenu[$i][1] = $bState
    Next

EndFunc   ;==>_Adjust_All

Func _Adjust_Parents($hPassedItem, $bState = True)

    Local $iIndex

    ; Get the handle of the parent
    Local $hParent = _GUICtrlTreeView_GetParentHandle($Check, $hPassedItem)
    If $hParent = 0 Then Return
    ; Assume parent is to be adjusted
    Local $bAdjustParent = True
    ; Need to confirm all siblings clear before clearing parent
    If $bState = False Then
        ; Check on number of siblings
        Local $iCount = _GUICtrlTreeView_GetChildCount($Check, $hParent)
        ; If only 1 sibling then parent can be cleared - if more then need to look at them all
        If $iCount <> 1 Then
            ; Number of siblings checked
            Local $iCheckCount = 0
            ; Move through previous siblings
            Local $hSibling = $hPassedItem
            While 1
                $hSibling = _GUICtrlTreeView_GetPrevSibling($Check, $hSibling)
                ; If found
                If $hSibling Then
                    ; Is sibling checked)
                    If _GUICtrlTreeView_GetChecked($Check, $hSibling) Then
                        ; Increase count if so
                        $iCheckCount += 1
                    EndIf
                Else
                    ; No point in continuing
                    ExitLoop
                EndIf
            WEnd
            ; Move through later siblings
            $hSibling = $hPassedItem
            While 1
                $hSibling = _GUICtrlTreeView_GetNextSibling($Check, $hSibling)
                If $hSibling Then
                    If _GUICtrlTreeView_GetChecked($Check, $hSibling) Then
                        $iCheckCount += 1
                    EndIf
                Else
                    ExitLoop
                EndIf
            WEnd
            ; If at least one sibling checked then do not clear parent
            If $iCheckCount Then $bAdjustParent = False
        EndIf
    EndIf
    ; If parent is to be adjusted
    If $bAdjustParent Then
        ; Adjust the array
        $iIndex = _ArraySearch($TreeMenu, $hParent)
        If @error Then Return
        $TreeMenu[$iIndex][1] = $bState
        ; Adjust the parent
        _GUICtrlTreeView_SetChecked($Check, $hParent, $bState)
        ; And now do the same for the generation above
        _Adjust_Parents($hParent, $bState)
    EndIf

EndFunc   ;==>_Check_Parents

Func _Adjust_Children($hPassedItem, $bState = True)

    Local $iIndex

    ; Get the handle of the first child
    Local $hChild = _GUICtrlTreeView_GetFirstChild($Check, $hPassedItem)
    If $hChild = 0 Then Return
    ; Loop through children
    While 1
        ; Adjust the array
        $iIndex = _ArraySearch($TreeMenu, $hChild)
        If @error Then Return
        $TreeMenu[$iIndex][1] = $bState
        ; Adjust the child
        _GUICtrlTreeView_SetChecked($Check, $hChild, $bState)
        ; And now do the same for the generation beow
        _Adjust_Children($hChild, $bState)
        ; Now get next child
        $hChild = _GUICtrlTreeView_GetNextChild($Check, $hChild)
        ; Exit the loop if no more found
        If $hChild = 0 Then ExitLoop
    WEnd

EndFunc   ;==>_Adjust_Children

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    ; Create NMTREEVIEW structure
    Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
            "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
            "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
            "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
            "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
            "struct;long PointX;long PointY;endstruct", $lParam)
    Local $hWndFrom = DllStructGetData($tStruct, "hWndFrom")
    If $hWndFrom = GUICtrlGetHandle($Check) Then
        Switch  DllStructGetData($tStruct, "Code")
            Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                Local $hItem = DllStructGetData($tStruct, "NewhItem")
                ; Set flag to selected item handle
                If $hItem Then $ItemSelected = $hItem
        EndSwitch
    EndIf
EndFunc

 

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