Jump to content

TreeView Check Boxes


gfunk999
 Share

Recommended Posts

Hey All, going :D

Is treeview limited to only one selection at a time? ;) I know there's a reason for checkboxes, but i'm failing to come up with a way to check multiple boxes and carry one set of instructions for the selected items. I looked through the forum, and the help files but all examples are for one box selection only; Well at least what I checked.

For example: Select multiple .exe files via checkboxes, and excute all of them with a click of a button.

Code a bit dirty, but that's the best I could come up with based on some forum examples ;)

#include <GuiTreeView.au3>
#include <GUIConstants.au3>


Local $drvgui, $nmsg, $find, $nxtfile, $Drvpath, $gettxt, $readtxt

$DrvPath = "C:\WINDOWS\system32\drivers\"

$drvgui = GUICreate("Drivers", 420, 550)
$treeview = GUICtrlCreateTreeView(10, 10, 400, 500, $TVS_CHECKBOXES)
$button1 = GUICtrlCreateButton("Do Something", 10, 520, 120, 20)

    GUISetState()
        $find = FileFindFirstFile($DrvPath & "*.*")

While 1
    $nxtfile = FileFindNextFile($find)
        If @error Then ExitLoop
            GUICtrlCreateTreeViewitem($nxtfile,$treeview)
WEnd

While 1
    $nmsg = GUIGetMsg()
    Switch $nmsg
        Case $GUI_EVENT_CLOSE
                GUIDelete($drvgui)
                ExitLoop
        Case $button1            
                $gettxt = GUICtrlRead($treeview)
                $readtxt = GUICtrlRead($gettxt, 1)
                MsgBox(0, "", $readtxt)
    EndSwitch
WEnd

Exit
Edited by gfunk999
Link to comment
Share on other sites

Hey All, going ;)

Is treeview limited to only one selection at a time? :lmao: I know there's a reason for checkboxes, but i'm failing to come up with a way to check multiple boxes and carry one set of instructions for the selected items. I looked through the forum, and the help files but all examples are for one box selection only; Well at least what I checked.

For example: Select multiple .exe files via checkboxes, and excute all of them with a click of a button.

Code a bit dirty, but that's the best I could come up with based on some forum examples ;)

#include <GuiTreeView.au3>
#include <GUIConstants.au3>


Local $drvgui, $nmsg, $find, $nxtfile, $Drvpath, $gettxt, $readtxt

$DrvPath = "C:\WINDOWS\system32\drivers\"

$drvgui = GUICreate("Drivers", 420, 550)
$treeview = GUICtrlCreateTreeView(10, 10, 400, 500, $TVS_CHECKBOXES)
$button1 = GUICtrlCreateButton("Do Something", 10, 520, 120, 20)

    GUISetState()
        $find = FileFindFirstFile($DrvPath & "*.*")

While 1
    $nxtfile = FileFindNextFile($find)
        If @error Then ExitLoop
            GUICtrlCreateTreeViewitem($nxtfile,$treeview)
WEnd

While 1
    $nmsg = GUIGetMsg()
    Switch $nmsg
        Case $GUI_EVENT_CLOSE
                GUIDelete($drvgui)
                ExitLoop
        Case $button1           
                $gettxt = GUICtrlRead($treeview)
                $readtxt = GUICtrlRead($gettxt, 1)
                MsgBox(0, "", $readtxt)
    EndSwitch
WEnd

Exit
You should be using ControlTreeView(). Use "GetItemCount", then walk the items doing "IsChecked" on each one to assemble a list of checked items. I don't think there is a command to get a collection of all checked items from a treeview in one stroke. This can also be done with the _GuiCtrlTreeView_* functions, but it works the same way.

BTW, since you are only assembling a list of files in one directory, a ListView might be easier to work with than a TreeView anyway. Then you have things like _GUICtrlListView_GetSelectedIndices() available.

If your full script will actually search a recursive path and make a real tree view of the found files, then you will have to make the search for checked items recursive through subitems too.

:D

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I'm currently using a tristate treeview for a testing process. What I have done is to create an array that I use to populate the treeview, and then use the following command to determine if it is checked.

It may not be the best example, but it's what works for me as I need to be able to have the information available to the system after a reboot.

For $icc = 0 to Ubound($Aarray)-1
$h = 0
if _GUICtrlTreeView_GetChecked($hTreeView, _GuiCtrlTreeView_FindItem($hTreeView, Aarray[$icc])) = True then $h = 1
$StringExample &= $h
Next

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

@PsaltyDS

Using ControlTreeView, IsChecked, and GetItemCount worked like a charm. Thank you!

@Kerros

Thank you Kerros i'll keep your advice for future reference.

GF

You should be using ControlTreeView(). Use "GetItemCount", then walk the items doing "IsChecked" on each one to assemble a list of checked items. I don't think there is a command to get a collection of all checked items from a treeview in one stroke. This can also be done with the _GuiCtrlTreeView_* functions, but it works the same way.

BTW, since you are only assembling a list of files in one directory, a ListView might be easier to work with than a TreeView anyway. Then you have things like _GUICtrlListView_GetSelectedIndices() available.

If your full script will actually search a recursive path and make a real tree view of the found files, then you will have to make the search for checked items recursive through subitems too.

;)

Edited by gfunk999
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...