Jump to content

Dynamically create a checkbox using GUICtrlCreateTreeView


ktc
 Share

Recommended Posts

Hi there,

Is there someone who can help me to create a gui with checkboxes that is based on a file. The content of the file change dynamically. The checkboxes must be able to set and then read the selected boxes to continue in the script for futher actions.

the goal is to read a list with filenames and then copy the selectes ones. the filnames a gathered from different places.

Thx.

Link to comment
Share on other sites

  • Moderators

ktc,

Welcome to the AutoIt forum. :)

When you post here it always helps if you have had a go at solving your problems beforehand. Having some code to work on is a great help - and no-one here is too keen to help the "code it for me" posters. Think of the old saying: "Give a man a fish, you feed him for a day; give a man a net and you feed him forever". We try to be net makers and repairers, not fishmongers. ;)

Reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page). There are even video tutorials on YouTube if you prefer watching to reading. ;)

So see what you can come up with - you know where we are if you run into difficulties. :)

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

Hi

I understand. See the code i have so far. I read the registry and put it in a ini. Then a filter on a specific extention an dwish to display this in a checkbox list. Then the checked items need to be copied.

; ==========================================================================================
;
; Script name:  ArcCopy.au3 - Compiled name ArcCopy.exe
;
; Description: ArcCopy.exe checks the existing of outlook archives in use and
;    copies the one selected by the user to his usershare
;
; ==========================================================================================
#include <File.au3>
#include <Array.au3>
#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#Include <Constants.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
;#NoTrayIcon
;Opt('MustDeclareVars', 1)
Global $strCatalog, $strArchive, $count, $strName, $stline, $strName2
Global $szDrive, $szDir, $szFName, $szExt, $strFile
Global $Next_Btn, $msg, $Background, $tmp
Global $archive1,$archive2, $archive3, $archive4, $archive5, $archive6
Global $treeview, $generalitem, $hListView, $file, $status, $hItem, $input
;$Process = "Outlook.exe"
While ProcessExists($Process)
Sleep (1000)
$Onclick = MsgBox(1, "ArcCopy", "Outlook must be closed to continue. Please Close Outlook and click OK. Click Cancel to exit. No futher actions will be preformed")
If $Onclick = 2 Then
  Exit
EndIf
WEnd
;MsgBox(1, "Stopped", $Process & " ended")
For $count = 1 To 10
; Read values below the catalog string to get all attached achive files
Local $strCatalog = RegEnumVal("HKEY_CURRENT_USERSoftwareMicrosoftOffice14.0OutlookSearchCatalog", $count)
If @error <> 0 Then ExitLoop
Local $strArchive = StringRight($strCatalog, 3)
;MsgBox(0, "Rightmost 3 characters are:", $strArchive)
If $strArchive = "pst" Then
  IniWrite(@TempDir & "archive.ini", "Archives", $count, $strCatalog)
EndIf
Next
_Main()
Local $var = IniReadSection(@TempDir & "archive.ini", "Archives")
If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
  Local $strFile = _PathSplit($var[$i][1], $szDrive, $szDir, $szFName, $szExt)
  If FileExists("U:TestArchive" & $strFile[3] & $strFile[4]) Then
   ; do nothing
  Else
   _FileCopy($var[$i][1],"U:TestArchive")
  EndIf
Next
EndIf

;************************************************************************************************
; Functions
;************************************************************************************************
Func _Main()
dim $gwidth, $gheight, $lleft, $ltop, $cleft, $ctop
$gwidth = 460
$gheight = 250
$lleft = 35
$ltop = 15
$cleft= 15
$ctop = 15
;************************************************************************************************
; GUI
;************************************************************************************************
; GUI
GuiCreate("Archive Online Backup", $gwidth, $gheight)
; BUTTONS
$Next_Btn = GuiCtrlCreateButton("Next",340, 180, 100, 30)
GuiCtrlCreateGroup("Archives", 5, 15, 440, 150)
$treeview = GUICtrlCreateTreeView(15, 35, 420, 120, BitOR($TVS_HASBUTTONS, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE)
_fill()
GUISetState()
;GUICtrlSetState($inpServerName,$gui_focus)
While 1
  $msg = GUIGetMsg()
  Select
   Case $msg = $GUI_EVENT_CLOSE
    Exit
   Case $msg = $Next_Btn
    _IsChecked($generalitem, $treeview)
    ;MsgBox(0, "" , "YOU CLICKT NEXT")
  EndSelect
WEnd
GUIDelete()
EndFunc   ;==>_Main

Func _FileCopy($strSource,$strDestination)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($strDestination).CopyHere($strSource,$FOF_RESPOND_YES)
EndFunc
Func _fill()
$var = IniReadSection(@TempDir & "archive.ini", "Archives")
;$var = IniReadSection("E:Mijn DocumentenMy ProjectenAutoItscriptsfilecopyinfo.ini", "aap")
$c = 1
If @error Then
  MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
  For $i = 1 To $var[0][0]
   $file = _PathSplit($var[$i][1], $szDrive, $szDir, $szFName, $szExt)
   $generalitem  = GUICtrlCreateTreeViewItem($file[3] & $file[4], $treeview)
  Next
EndIf
EndFunc

Func _IsChecked($generalitem, $treeview)
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($generalitem))
$hItem = _GUICtrlTreeView_GetFirstItem($treeview)
;MsgBox(0, "", $treeview)
Do
  $status = _GUICtrlTreeView_GetChecked ($treeview, $hItem)
  If $status Then
   $status = "yes"
   GUICtrlCreateListViewItem(GUICtrlRead($input) & _GUICtrlTreeView_GetText($treeview, $hItem) & "|" & $status,  $generalitem)
  EndIf
  MsgBox(0, "", $hItem & @CRLF & $status)
  $hItem = _GUICtrlTreeView_GetNextSibling($treeview, $hItem)
Until Not $hItem

EndFunc
Link to comment
Share on other sites

  • Moderators

ktc,

You appear to be mixing up functions for ListViews and TreeViews in your _IsChecked function - which do you want as they are very different beasts. ;)

And as I do not have OutLook installed, can you please post a copy of an archive.ini file so I can work on the code. :)

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

Hi M23,

Thnx for your guidance.

Attached the ini file (i renamed it to .txt because it was not allowwed to upload a .ini). The goal is present the enduser the attached archives and let him/her choose which ones should be copied. Thats where I got confused.

ktc

archive.ini.txt

Link to comment
Share on other sites

  • Moderators

ktc,

You still did not say whether you wanted a ListView or TreeView - so I have used a ListView as it is more appropriate for this type of thing. ;)

Try this script. I had to make a few changes to get it to work on my system - it should be obvious where these are:

; ==========================================================================================
;
; Script name:  ArcCopy.au3 - Compiled name ArcCopy.exe
;
; Description: ArcCopy.exe checks the existing of outlook archives in use and
;   copies the one selected by the user to his usershare
;
; ==========================================================================================
#include <file.au3>
#include <array.au3>
#include <guiconstantsex.au3>
#include <editconstants.au3>
#include <buttonconstants.au3>
#include <comboconstants.au3>
#include <constants.au3>
#include <windowsconstants.au3>
#include <treeviewconstants.au3>
#include <staticconstants.au3>
#include <guilistview.au3>
#include <guitreeview.au3>
;#NoTrayIcon
;Opt('MustDeclareVars', 1)
Global $strCatalog, $strArchive, $count, $strName, $stline, $strName2
Global $szDrive, $szDir, $szFName, $szExt, $strFile
Global $Next_Btn, $msg, $Background, $tmp
Global $archive1, $archive2, $archive3, $archive4, $archive5, $archive6
Global $listview, $generalitem, $hListView, $file, $status, $hItem, $input
$Process = "Outlook.exe"
While ProcessExists($Process)
    Sleep(1000)
    $Onclick = MsgBox(1, "ArcCopy", "Outlook must be closed to continue. Please Close Outlook and click OK. Click Cancel to exit. No futher actions will be preformed")
    If $Onclick = 2 Then
        Exit
    EndIf
WEnd
;MsgBox(1, "Stopped", $Process & " ended")
#cs
    For $count = 1 To 10
    ; Read values below the catalog string to get all attached achive files
    Local $strCatalog = RegEnumVal("HKEY_CURRENT_USERSoftwareMicrosoftOffice14.0OutlookSearchCatalog", $count)
    If @error <> 0 Then ExitLoop
    Local $strArchive = StringRight($strCatalog, 3)
    ;MsgBox(0, "Rightmost 3 characters are:", $strArchive)
    If $strArchive = "pst" Then
    IniWrite(@TempDir & "archive.ini", "Archives", $count, $strCatalog)
    EndIf
    Next
#ce

_Main()

Local $var = IniReadSection(@ScriptDir & "archive.ini", "Fred")
If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
        Local $strFile = _PathSplit($var[$i][1], $szDrive, $szDir, $szFName, $szExt)
        If FileExists("U:TestArchive" & $strFile[3] & $strFile[4]) Then
            ; do nothing
        Else
            ;_FileCopy($var[$i][1], "U:TestArchive")
        EndIf
    Next
EndIf

;************************************************************************************************
; Functions
;************************************************************************************************
Func _Main()
    Dim $gwidth, $gheight, $lleft, $ltop, $cleft, $ctop
    $gwidth = 460
    $gheight = 250
    $lleft = 35
    $ltop = 15
    $cleft = 15
    $ctop = 15
    ;************************************************************************************************
    ; GUI
    ;************************************************************************************************
    ; GUI
    GUICreate("Archive Online Backup", $gwidth, $gheight)
    ; BUTTONS
    $Next_Btn = GUICtrlCreateButton("Next", 340, 180, 100, 30)
    GUICtrlCreateGroup("Archives", 5, 15, 440, 150)
    $listview = GUICtrlCreateListView("", 15, 35, 420, 120, BitOr($LVS_SHOWSELALWAYS, $LVS_NOCOLUMNHEADER), $WS_EX_CLIENTEDGE)
    _GUICtrlListView_SetExtendedListViewStyle($listview, $LVS_EX_CHECKBOXES)
    _GUICtrlListView_AddColumn($listview, "Available Archives", 380)
    _fill()
    GUISetState()
    ;GUICtrlSetState($inpServerName,$gui_focus)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $Next_Btn
                _FileCopy()
        EndSelect
    WEnd
    GUIDelete()
EndFunc   ;==>_Main

Func _FileCopy() ; $strSource, $strDestination)

    For $i = 0 To _GUICtrlListView_GetItemCount($listview) - 1
        $status = _GUICtrlListView_GetItemChecked($listview, $i)
        If $status Then
            ConsoleWrite("Copy function for " & _GUICtrlListView_GetItemText($listview, $i) & @CRLF)
            ;Local $FOF_RESPOND_YES = 16
            ;Local $FOF_SIMPLEPROGRESS = 256
            ;$winShell = ObjCreate("shell.application")
            ;$winShell.namespace($strDestination).CopyHere($strSource, $FOF_RESPOND_YES)
        EndIf
    Next
    _GUICtrlListView_DeleteAllItems($listview)

EndFunc   ;==>_FileCopy

Func _fill()
    $var = IniReadSection(@ScriptDir & "archive.ini", "Archives")
    ;$var = IniReadSection("E:Mijn DocumentenMy ProjectenAutoItscriptsfilecopyinfo.ini", "aap")
    $c = 1
    If @error Then
        MsgBox(4096, "", "Error occurred, probably no INI file.")
    Else
        For $i = 1 To $var[0][0]
            _PathSplit($var[$i][1], $szDrive, $szDir, $szFName, $szExt)
            GUICtrlCreateListViewItem($szFName, $listview)
        Next
    EndIf
EndFunc   ;==>_fill

Func _IsChecked($generalitem, $listview)

EndFunc   ;==>_IsChecked

Is that what you wanted? :)

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

Hi M23,

This is perfect. From this step on I can start the copy process and present our users the option to store their archives in the exchange online archives.

tnx for your help. :)

Kind Regards, ;)

ktc

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