Sign in to follow this  
Followers 0
kgreer

GUI TreeView with checkboxes help

6 posts in this topic

I am writing a script to dynamically create a TreeView control with checkboxes from a INI file containing a list of items. I do not see a function to get the items selected from the treeview. I might be overcomplicating this, but is there an example on how to get the selected items from the treeview?

Share this post


Link to post
Share on other sites



kgreer,

Loop through the items by index (remember they are 0-based) and use _GUICtrlTreeView_GetChecked to see which ones are checked. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thanks! However I'm missing something. Here is what I'm working with. Once I figure out the functions I will modify this to my needs. I'm not getting a True prompt for the 3rd checked item and instead of 4 msg boxes, there is 5 in the loop. What am I missing?

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
GUISetState(@SW_SHOW)
Local $iTreeView_2 = GUICtrlCreateTreeView(30, 30, 200, 160, $TVS_CHECKBOXES)
GUICtrlCreateTreeViewItem("TreeView", $iTreeView_2)
GUICtrlCreateTreeViewItem("With", $iTreeView_2)
GUICtrlCreateTreeViewItem("$TVS_CHECKBOXES", $iTreeView_2)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateTreeViewItem("Style", $iTreeView_2)

$count = _GUICtrlTreeView_GetCount($iTreeView_2)
for $i=1 to $count
msgbox(0,"ischecked",_GUICtrlTreeView_GetChecked($iTreeView_2,$i))
Next

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

Share this post


Link to post
Share on other sites

kgreer,

The Help file says you need to pass the handle of the TreeViewItem to that function - so we need to collect them as the items are created:

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

Global $aItems[4]

$Form1 = GUICreate("Form1", 500, 500)
GUISetState(@SW_SHOW)

Local $iTreeView_2 = GUICtrlCreateTreeView(30, 30, 200, 160, $TVS_CHECKBOXES)
$aItems[0] = GUICtrlGetHandle(GUICtrlCreateTreeViewItem("TreeView", $iTreeView_2))
$aItems[1] = GUICtrlGetHandle(GUICtrlCreateTreeViewItem("With", $iTreeView_2))
$aItems[2] = GUICtrlGetHandle(GUICtrlCreateTreeViewItem("TVS_CHECKBOXES", $iTreeView_2))
_GUICtrlTreeView_SetChecked($iTreeView_2, $aItems[2])
$aItems[3] = GUICtrlGetHandle(GUICtrlCreateTreeViewItem("Style", $iTreeView_2))

$cButton = GUICtrlCreateButton("Read", 10, 450, 80, 30)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            $count = _GUICtrlTreeView_GetCount($iTreeView_2)
            For $i = 0 To $count - 1
                MsgBox(0, "ischecked", $i & " = " & _GUICtrlTreeView_GetChecked($iTreeView_2, $aItems[$i]))
            Next
    EndSwitch
WEnd

All clear? :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Ahh I see. Thanks. You got me a jump start. I'll work on my project and chime in again if I need help. Thanks!

Share this post


Link to post
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
Sign in to follow this  
Followers 0