Jump to content
Sign in to follow this  

single-item or multiple-item selection in TreeView

Recommended Posts


You can disregard this one, I found some information in other posts.



I have a question about single-item or multiple-item selection in a TreeView. I couldn't find a way to avoid the multiple selection.

I want to create a configuration page with a number of TreeViews and with variable amounts of data rows per selection.

To illustrate what I mean, see the attached example.

Let's assume you have a variable amount of grouped items to be selected Some of the TreeViews allow miltiple selections where other only can accept one single choice. For simplicity, the example has only 1 amount of items (20)

Col 1: is a simple treeview with $TVS_CHECKBOXES. Perfect works fine for multi-selects.

Col 2: is what I want but I can't achieve. Same TreeView but only one check-box should be selected. (the example is the same as col 1.

Col 3: the radio button alternative, not as flexible because of the missing scroll bar. Where are items 10+ in the example?

Col 4: This works, a simple combo box with the default item selected. Only one item can be seleceted at a time. What I miss here is a standard way to present data to the user.

So the question is, Can I make row 2 but with the limitation that only one check-box can be selected?


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)

Local $Elements = 20


Func Example($_Elements)
    Local $treeview, $OKbutton, $cancelbutton, $msg

    DIM $Columns[$_Elements][6] 
    GUICreate("Test GUI with treeview", 800, 215)

    GUICtrlCreateLabel("multiple-item select", 10, 10, 110,18) 

    Local $TreeView = GuiCtrlCreateTreeView(10, 30, 110, 120, $TVS_CHECKBOXES)
    For $i = 0 To UBound($Columns)-1
        $Columns[$i][1] = GuiCtrlCreateTreeViewItem("Column " & $i + 1, $TreeView)
        If $i + 1 = 5 or $i + 1 = 6 Then
            GuiCtrlSetState(-1, $GUI_CHECKED) ; check if column match with list     
    GUICtrlCreateLabel("single-item select???", 130, 10, 110,18) 
    Local $TreeView = GuiCtrlCreateTreeView(130, 30, 110, 120, $TVS_CHECKBOXES)
    For $i = 0 To UBound($Columns)-1
        $Columns[$i][2] = GuiCtrlCreateTreeViewItem("Column " & $i + 1, $TreeView)
        If $i +1 = 2 Then
            GuiCtrlSetState(-1, $GUI_CHECKED) ; Checked

    GUICtrlCreateLabel("Radio button", 260, 10, 110,18) 
    For $i = 0 To UBound($Columns)-1
        $Columns[$i][3] = GUICtrlCreateRadio("Column " & $i + 1, 260, 30 + ($i * 20), 110, 20)
        If $i + 1 = 12 Then
            GuiCtrlSetState(-1, $GUI_CHECKED) ; Default selection

    GUICtrlCreateLabel("Combo", 370, 10, 110,18) 
    Local $Items = "None|", $DefaultItem = ""
    For $i = 0 To UBound($Columns)-1
        $items = $items & "Column " & $i + 1 & "|"
        If $i + 1 = 10 Then
            $DefaultItem = "Column " & $i + 1 ; Default selection   
    GUICtrlCreateCombo("", 370, 30, 110, 60) ; create first item
    GUICtrlSetData(-1, $items, $DefaultItem) ; add other item snd set a new default
    $OKbutton = GUICtrlCreateButton("&OK", 35, 185, 70, 20)
    $cancelbutton = GUICtrlCreateButton("&Cancel", 125, 185, 70, 20)
    While 1
        $msg = GUIGetMsg()
            Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE

            Case $msg = $OKbutton   ; Toggle the bold painting


EndFunc   ;==>Example
Edited by GreenCan


CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image




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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.