MrCreatoR

How to get Index of selected TreeView item?

8 posts in this topic

Hi,

Again a TreeView related question: What is the correct way to get Index of currently selected item? and i need the index relative to the very first item.

Here is my code, when i select Item8 for example, i want to get «Index: 8» not «Index: 0», or when i select Item5, i want to get «Index: 5» not «Index: 2» (the item names can be anything of course)...

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

$GUI = GUICreate("Test Script", 230, 300)

$TreeView = GUICtrlCreateTreeView(15, 20, 200, 230, -1, $WS_EX_CLIENTEDGE)

Global $aItems[11]

For $i = 1 To 10
    If Mod($i, 2) <> 0 Then
        $aItems[$i] = GUICtrlCreateTreeViewItem("Item" & $i, $TreeView)
    Else
        $aItems[$i] = GUICtrlCreateTreeViewItem("Item" & $i, -1)
    EndIf
    
    GUICtrlSetState($i+2, $GUI_EXPAND)
Next

$GetIndex_Button = GUICtrlCreateButton("Get Index", 20, 270, 60, 20)

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GetIndex_Button
            $hSelected_Item = _GUICtrlTreeView_GetSelection($TreeView)
            $iIndex = _GUICtrlTreeView_Index($TreeView, $hSelected_Item)
            
            MsgBox(64, "", StringFormat("Selected Text: %s\nSelected Index: %i", GUICtrlRead($TreeView, 1), $iIndex), 0, $GUI)
    EndSwitch
WEnd

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites



Ok, i think i found a way:

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

$GUI = GUICreate("Test Script", 230, 300)

$TreeView = GUICtrlCreateTreeView(15, 20, 200, 230, -1, $WS_EX_CLIENTEDGE+$WS_EX_DLGMODALFRAME)

Global $aItems[11]

For $i = 1 To 10
    If Mod($i, 2) <> 0 Then
        $aItems[$i] = GUICtrlCreateTreeViewItem("Item" & $i, $TreeView)
    Else
        $aItems[$i] = GUICtrlCreateTreeViewItem("Item" & $i, -1)
    EndIf
    
    GUICtrlSetImage(-1, "Shell32.dll", -5, 3)
    GUICtrlSetImage(-1, "Shell32.dll", -4, 4)
    
    GUICtrlSetState($i+2, $GUI_EXPAND)
Next

$GetIndex_Button = GUICtrlCreateButton("Get Index", 20, 270, 60, 20)

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GetIndex_Button
            $iIndex = 0
            
            $hItem = _GUICtrlTreeView_GetFirstItem($TreeView)
            
            For $i = 0 To _GUICtrlTreeView_GetCount($TreeView)-1
                If _GUICtrlTreeView_GetSelected($TreeView, $hItem) Then $iIndex = $i+1
                
                $hItem = _GUICtrlTreeView_GetNext($TreeView, $hItem)
            Next
            
            MsgBox(64, "", StringFormat("Selected Text: %s\nSelected Index: %i", GUICtrlRead($TreeView, 1), $iIndex), 0, $GUI)
    EndSwitch
WEnd

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Another way:

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

$GUI = GUICreate("Test Script", 230, 300)

$TreeView = GUICtrlCreateTreeView(15, 20, 200, 230, -1, $WS_EX_CLIENTEDGE)

Global $aItems[11]
$aItems[0] = 10

For $i = 1 To 10
    If Mod($i, 2) <> 0 Then
        $aItems[$i] = GUICtrlCreateTreeViewItem("Item" & $i, $TreeView)
    Else
        $aItems[$i] = GUICtrlCreateTreeViewItem("Item" & $i, -1)
    EndIf
    
    GUICtrlSetState($i+2, $GUI_EXPAND)
Next

$GetIndex_Button = GUICtrlCreateButton("Get Index", 20, 270, 60, 20)

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GetIndex_Button
            $hSelected_Item = _GUICtrlTreeView_GetSelection($TreeView)
            
            For $i = 1 To $aItems[0]
                If $hSelected_Item = _GUICtrlTreeView_GetItemHandle($TreeView, $aItems[$i]) Then
                    $iIndex = $i
                    ExitLoop
                EndIf
            Next
            
            ConsoleWrite("Selected Index = " & $iIndex & @LF)
    EndSwitch
WEnd

:)

1 person likes this

Share this post


Link to post
Share on other sites

MrCreatoR

Your solution is good, but needs a little modification with this snippet:

original

$iIndex = 0
            
            $hItem = _GUICtrlTreeView_GetFirstItem($TreeView)
            
            For $i = 0 To _GUICtrlTreeView_GetCount($TreeView)-1
                If _GUICtrlTreeView_GetSelected($TreeView, $hItem) Then $iIndex = $i+1
                
                $hItem = _GUICtrlTreeView_GetNext($TreeView, $hItem)
            NextoÝ÷ Ù³(v'âyßÛjëh×6For $i = 0 To _GUICtrlTreeView_GetCount($TreeView)-1
                If _GUICtrlTreeView_GetSelected($TreeView, $hItem) Then
                    $iIndex = $i+1
                    ExitLoop
                EndIf
                
                $hItem = _GUICtrlTreeView_GetNext($TreeView, $hItem)
            Next

:)

Share this post


Link to post
Share on other sites

rasim

Modified

That's exactly how i did in my original script! Posted Image

Thanks!


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

hi MrCreatoR

thank you for this elaboration. i nearly went crazy in fumbling this out by myself.

for learning purposes, i extracted the UDFs out of the includes. it is hard to believe, but there are 150 codelines (without the WinAPI), just to realize this simple GetCursorSelect function !

:D j.

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
;#include <GuiTreeView.au3>
#include <TreeViewConstants.au3>
#include <WinAPI.au3>

Global $__ghTVLastWnd, $Debug_TV = 0, $__TREEVIEWCONSTANT_ClassName = "SysTreeView32" 

$GUI = GUICreate("Test Script", 230, 300)

$TreeView = GUICtrlCreateTreeView(15, 20, 200, 230, -1, $WS_EX_CLIENTEDGE + $WS_EX_DLGMODALFRAME)

Global $aItems[11]

For $i = 1 To 10
    If Mod($i, 2) <> 0 Then
        $aItems[$i] = GUICtrlCreateTreeViewItem("Item" & $i, $TreeView)
    Else
        $aItems[$i] = GUICtrlCreateTreeViewItem("Item" & $i, -1)
    EndIf

    GUICtrlSetImage(-1, "Shell32.dll", -5, 3)
    GUICtrlSetImage(-1, "Shell32.dll", -4, 4)

    GUICtrlSetState($i + 2, $GUI_EXPAND)
Next

$GetIndex_Button = GUICtrlCreateButton("Get Index", 20, 270, 60, 20)

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GetIndex_Button
            $iIndex = 0

            $hItem = _GUICtrlTreeView_GetFirstItem($TreeView)

            For $i = 0 To _GUICtrlTreeView_GetCount($TreeView) - 1
                If _GUICtrlTreeView_GetSelected($TreeView, $hItem) Then $iIndex = $i + 1

                $hItem = _GUICtrlTreeView_GetNext($TreeView, $hItem)
            Next

            MsgBox(64, "", StringFormat("Selected Text: %s\nSelected Index: %i", GUICtrlRead($TreeView, 1), $iIndex), 0, $GUI)
    EndSwitch
WEnd

Func _GUICtrlTreeView_GetFirstItem($hWnd)
    If $Debug_TV Then _GUICtrlTreeView_ValidateClassName($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    
    Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_ROOT, 0, 0, "wparam", "lparam", "hwnd")
EndFunc   ;==>_GUICtrlTreeView_GetFirstItem

Func _GUICtrlTreeView_GetCount($hWnd)
    If $Debug_TV Then _GUICtrlTreeView_ValidateClassName($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    
    Return _SendMessage($hWnd, $TVM_GETCOUNT)
EndFunc   ;==>_GUICtrlTreeView_GetCount

Func _GUICtrlTreeView_GetSelected($hWnd, $hItem)
    Return BitAND(_GUICtrlTreeView_GetState($hWnd, $hItem), $TVIS_SELECTED) <> 0
EndFunc   ;==>_GUICtrlTreeView_GetSelected

Func _GUICtrlTreeView_GetState($hWnd, $hItem = 0)
    If $Debug_TV Then _GUICtrlTreeView_ValidateClassName($hWnd)
    Local $tTVITEM, $iSize, $tMemMap, $pItem, $pMemory
    If $hItem = 0 Then $hItem = 0x00000000
    
    $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
    If $hItem = 0x00000000 Then Return SetError(1, 1, 0)
    
    $tTVITEM = DllStructCreate($tagTVITEMEX)
    $pItem = DllStructGetPtr($tTVITEM)
    DllStructSetData($tTVITEM, "Mask", $TVIF_STATE)
    DllStructSetData($tTVITEM, "hItem", $hItem)
    
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    If _WinAPI_InProcess ($hWnd, $__ghTVLastWnd) Then
        _SendMessage($hWnd, $TVM_GETITEM, 0, $pItem)
    Else
        $iSize = DllStructGetSize($tTVITEM)
        $pMemory = _MemInit ($hWnd, $iSize, $tMemMap)
        _MemWrite ($tMemMap, $pItem)
        _SendMessage($hWnd, $TVM_GETITEM, 0, $pMemory)
        _MemRead ($tMemMap, $pMemory, $pItem, $iSize)
        _MemFree ($tMemMap)
    EndIf
;~  If _SendMessage($hWnd, $TVM_GETITEM, 0, $pItem) = 0 Then Return 0
    
    Return DllStructGetData($tTVITEM, "State")
EndFunc   ;==>_GUICtrlTreeView_GetState

Func _GUICtrlTreeView_GetItemHandle($hWnd, $hItem = 0)
    If $Debug_TV Then _GUICtrlTreeView_ValidateClassName($hWnd)
    Local $hTempItem
    If $hItem = 0 Then $hItem = 0x00000000
    If IsHWnd($hWnd) Then
        If $hItem = 0x00000000 Then $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_ROOT, 0, 0, "wparam", "lparam", "hwnd")
    Else
        If $hItem = 0x00000000 Then
            $hItem = GUICtrlSendMsg($hWnd, $TVM_GETNEXTITEM, $TVGN_ROOT, 0)
        Else
            $hTempItem = GUICtrlGetHandle($hItem)
            If $hTempItem <> 0x00000000 Then $hItem = $hTempItem
        EndIf
    EndIf
    
    Return $hItem
EndFunc   ;==>_GUICtrlTreeView_GetItemHandle

Func _GUICtrlTreeView_GetNext($hWnd, $hItem)
    Local $hNext, $hParent, $hResult
    If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    $hResult = 0
    If $hItem <> 0x00000000 And $hItem <> 0 Then
        $hNext = _GUICtrlTreeView_GetFirstChild($hWnd, $hItem)
        If $hNext = 0x00000000 Then
            $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hItem)
        EndIf
        $hParent = $hItem
        While ($hNext = 0x00000000) And ($hParent <> 0x00000000)
            $hParent = _GUICtrlTreeView_GetParentHandle ($hWnd, $hParent)
            If $hParent = 0x00000000 Then
                $hNext = 0x00000000
                ExitLoop
            EndIf
            $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hParent)
        WEnd
        If $hNext = 0x00000000 Then $hNext = 0
        $hResult = $hNext
    EndIf
    Return $hResult
EndFunc   ;==>_GUICtrlTreeView_GetNext

Func _GUICtrlTreeView_GetFirstChild($hWnd, $hItem)
    If $Debug_TV Then _GUICtrlTreeView_ValidateClassName($hWnd)
    If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    
    Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CHILD, $hItem, 0, "wparam", "hwnd", "hwnd")
EndFunc   ;==>_GUICtrlTreeView_GetFirstChild

Func _GUICtrlTreeView_GetNextSibling($hWnd, $hItem)
    If $Debug_TV Then _GUICtrlTreeView_ValidateClassName($hWnd)
    If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    
    Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_NEXT, $hItem, 0, "wparam", "hwnd", "hwnd")
EndFunc   ;==>_GUICtrlTreeView_GetNextSibling

Func _GUICtrlTreeView_GetParentHandle($hWnd, $hItem = 0)
    If $Debug_TV Then _GUICtrlTreeView_ValidateClassName($hWnd)
;~  If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    
    Local $hParent
    If $hItem = 0 Then $hItem = 0x00000000
    
    ; get the handle to item selected
    If $hItem = 0x00000000 Then
        If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
        $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0, 0, "wparam", "hwnd", "hwnd")
        If $hItem = 0x00000000 Then Return False
    Else
        If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
        If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    EndIf
    ; get the handle of the parent item
    $hParent = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem, 0, "wparam", "hwnd", "hwnd")

    Return $hParent
EndFunc   ;==>_GUICtrlTreeView_GetParentHandle

Func _GUICtrlTreeView_ValidateClassName($hWnd)
    _GUICtrlTreeView_DebugPrint("This is for debugging only, set the debug variable to false before submitting")
    _WinAPI_ValidateClassName ($hWnd, $__TREEVIEWCONSTANT_ClassName)
EndFunc   ;==>_GUICtrlTreeView_ValidateClassName

Func _GUICtrlTreeView_DebugPrint($sText, $iLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $iLine) & "):" & @TAB & $sText & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_GUICtrlTreeView_DebugPrint

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Here is a super simple way to get item information in a treeview. Just use "GUIOnEventMode"

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GUITreeview.au3>


Opt("GUIOnEventMode", 1)

Global $aItems[16]

$hGUI = GUICreate("Treeview Example", 220, 320)
$hTreeView = GUICtrlCreateTreeView(10, 10, 200, 300)
GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")

$tParent = GUICtrlCreateTreeViewItem("Parent", $hTreeView)
GUICtrlSetOnEvent($hTreeView, "_Get_Info")

For $i = 1 To 15
        $aItems[$i] = GUICtrlCreateTreeViewItem("Item " & $i, $tParent)
    GUICtrlSetOnEvent($aItems[$i], "_Get_Info")
Next

_GUICtrlTreeView_Expand($hTreeView)

While 1
Wend

Func _Get_Info()
    Local $ID = GUICtrlRead($hTreeView)
    Local $Handle = _GUICtrlTreeView_GetItemHandle($hTreeView, $ID)
    Local $Text = _GUICtrlTreeView_GetText($hTreeView, $Handle)
    Msgbox(0, "Treeview Example", "ID = " & $ID & @CRLF & "Handle = " & $Handle & @CRLF & "Text = " & $Text & @CRLF)
EndFunc

Func _Close()
    Exit
EndFUnc

Treeview_Example.au3

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites

AndrewDaoust,

In future, please do not necro-post in 7 year old threads.

And when you post code please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.

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

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