Jump to content
Sign in to follow this  
Alexander

Reading selected item on TreeView

Recommended Posts

Alexander

Topic says it all, is there a way to read what is selected in a TreeView?

Share this post


Link to post
Share on other sites
Alexander

GUICtrlRead ( $TreeView ) - return control ID of selected item.

<{POST_SNAPBACK}>

is there a way to change that into the actual text?

Share this post


Link to post
Share on other sites
Alexander

No with release version, but this is possible in the current beta version, by reading given treeviewitem with GUICtrlRead in "advanced" mode. Check this here.

<{POST_SNAPBACK}>

I have installed the beta version, the help file does not document an advance mode of GUICtrlRead, please clarify.

Share this post


Link to post
Share on other sites
Fur

I too am battling this same issue today..

Share this post


Link to post
Share on other sites
Lazycat

Ops, probably JPM forgot include example for advanced mode into beta release. Here is example from previous "autoitspecial" release.

#include <GUIConstants.au3>

Global Const $LVS_EX_CHECKBOXES = 0x00000004

GUICreate("test",500,300)

Global $menu1       = GUICtrlCreateMenu("Menu1")
Global $menu2       = GUICtrlCreateMenu("Menu2")
Global $menuitem1   = GUICtrlCreateMenuItem("Item1",$menu1)
Global $menuitem2   = GUICtrlCreateMenuItem("Item2",$menu1)

Global $listview    = GUICtrlCreateListView("Col1|Col2",10,10,150,100,-1,BitOr($LVS_EX_CHECKBOXES,$WS_EX_CLIENTEDGE))
Global $lvitem1     = GUICtrlCreateListViewItem("Val1|Val2",$listview)
Global $lvitem2     = GUICtrlCreateListViewItem("Val3|Val4",$listview)

Global $treeview    = GUICtrlCreateTreeView(200,10,150,100,BitOr($TVS_CHECKBOXES,$TVS_SHOWSELALWAYS),$WS_EX_CLIENTEDGE)
Global $tvitem1     = GUICtrlCreateTreeViewItem("Item1",$treeview)
Global $tvitem2     = GUICtrlCreateTreeViewItem("Item2",$treeview)

Global $buttoncheck = GUICtrlCreateButton("CheckRead",100,250,70,20);
Global $buttontree  = GUICtrlCreateButton("TreeRead",220,250,70,20);
Global $buttonmenu  = GUICtrlCreateButton("MenuRead",10,250,70,20);

Global $checkbox    = GUICtrlCreateCheckbox("Check it",50,150,100,20)

Global $modecheck   = GUICtrlCreateCheckbox("Advanced Mode",200,150,100,20,$BS_PUSHLIKE);


GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $lvitem1
            Msgbox(0,"",GUICtrlRead($lvitem1))
            
        Case $msg = $lvitem2
            $result = GUICtrlRead($lvitem2,1)
            If IsArray($result) Then
                Msgbox(0,"",$result[0] & @LF & $result[1])
            EndIf
            
        Case $msg = $tvitem1
            Msgbox(0,"",GUICtrlRead($tvitem1))
            
        Case $msg = $tvitem2
            $result = GUICtrlRead($tvitem2,1)
            If IsArray($result) Then
                Msgbox(0,"",$result[0] & @LF & $result[1])
            EndIf
        
        Case $msg = $buttonmenu
            CtrlInfo($menu1)
            
        Case $msg = $buttoncheck
            CtrlInfo($checkbox)
            
        Case $msg = $buttontree
            CtrlInfo($treeview)
    EndSelect
WEnd

GUIDelete()
Exit

Func CtrlInfo($ctrlid)
    Local $ctrlid
    
    If GUICtrlRead($modecheck) = $GUI_CHECKED Then
        $result = GUICtrlRead($ctrlid,1)
    Else
        $result = GUICtrlRead($ctrlid)
    EndIf
    If IsArray($result) Then
        Msgbox(0,"Read",$result[0] & @LF & $result[1])
    Else
        Msgbox(0,"Read",$result)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
spytek_98

Ops, probably JPM forgot include example for advanced mode into beta release. Here is example from previous "autoitspecial" release.

#include <GUIConstants.au3>

Global Const $LVS_EX_CHECKBOXES = 0x00000004

GUICreate("test",500,300)

Global $menu1       = GUICtrlCreateMenu("Menu1")
Global $menu2       = GUICtrlCreateMenu("Menu2")
Global $menuitem1   = GUICtrlCreateMenuItem("Item1",$menu1)
Global $menuitem2   = GUICtrlCreateMenuItem("Item2",$menu1)

Global $listview    = GUICtrlCreateListView("Col1|Col2",10,10,150,100,-1,BitOr($LVS_EX_CHECKBOXES,$WS_EX_CLIENTEDGE))
Global $lvitem1     = GUICtrlCreateListViewItem("Val1|Val2",$listview)
Global $lvitem2     = GUICtrlCreateListViewItem("Val3|Val4",$listview)

Global $treeview    = GUICtrlCreateTreeView(200,10,150,100,BitOr($TVS_CHECKBOXES,$TVS_SHOWSELALWAYS),$WS_EX_CLIENTEDGE)
Global $tvitem1     = GUICtrlCreateTreeViewItem("Item1",$treeview)
Global $tvitem2     = GUICtrlCreateTreeViewItem("Item2",$treeview)

Global $buttoncheck = GUICtrlCreateButton("CheckRead",100,250,70,20);
Global $buttontree  = GUICtrlCreateButton("TreeRead",220,250,70,20);
Global $buttonmenu  = GUICtrlCreateButton("MenuRead",10,250,70,20);

Global $checkbox    = GUICtrlCreateCheckbox("Check it",50,150,100,20)

Global $modecheck   = GUICtrlCreateCheckbox("Advanced Mode",200,150,100,20,$BS_PUSHLIKE);
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $lvitem1
            Msgbox(0,"",GUICtrlRead($lvitem1))
            
        Case $msg = $lvitem2
            $result = GUICtrlRead($lvitem2,1)
            If IsArray($result) Then
                Msgbox(0,"",$result[0] & @LF & $result[1])
            EndIf
            
        Case $msg = $tvitem1
            Msgbox(0,"",GUICtrlRead($tvitem1))
            
        Case $msg = $tvitem2
            $result = GUICtrlRead($tvitem2,1)
            If IsArray($result) Then
                Msgbox(0,"",$result[0] & @LF & $result[1])
            EndIf
        
        Case $msg = $buttonmenu
            CtrlInfo($menu1)
            
        Case $msg = $buttoncheck
            CtrlInfo($checkbox)
            
        Case $msg = $buttontree
            CtrlInfo($treeview)
    EndSelect
WEnd

GUIDelete()
Exit

Func CtrlInfo($ctrlid)
    Local $ctrlid
    
    If GUICtrlRead($modecheck) = $GUI_CHECKED Then
        $result = GUICtrlRead($ctrlid,1)
    Else
        $result = GUICtrlRead($ctrlid)
    EndIf
    If IsArray($result) Then
        Msgbox(0,"Read",$result[0] & @LF & $result[1])
    Else
        Msgbox(0,"Read",$result)
    EndIf
EndFunc

<{POST_SNAPBACK}>

Cool example

I understand hwo to read the checkbox value, but how do set checkbox value for a GUICtrlCreateTreeViewItem?

Share this post


Link to post
Share on other sites
spytek_98

It's pretty easy with GUICtrlSetState() with $GUI_CHECKED/$GUI_UNCHECKED states.

<{POST_SNAPBACK}>

GUICtrlSetState() with $GUI_CHECKED didnt work... unless I did something wrong?

Here is my example below (based off yours).

Thanks

#include <GUIConstants.au3>

Global Const $LVS_EX_CHECKBOXES = 0x00000004

GUICreate("test",500,300)

Global $menu1       = GUICtrlCreateMenu("Menu1")
Global $menu2       = GUICtrlCreateMenu("Menu2")
Global $menuitem1   = GUICtrlCreateMenuItem("Item1",$menu1)
Global $menuitem2   = GUICtrlCreateMenuItem("Item2",$menu1)

Global $listview    = GUICtrlCreateListView("Col1|Col2",10,10,150,100,-1,BitOr($LVS_EX_CHECKBOXES,$WS_EX_CLIENTEDGE))
Global $lvitem1     = GUICtrlCreateListViewItem("Val1|Val2",$listview)
Global $lvitem2     = GUICtrlCreateListViewItem("Val3|Val4",$listview)

GUICtrlSetState($lvitem2, $GUI_CHECKED); Does not work for listview. (using  AutoIt3.1.0.15J.zip)

Global $treeview    = GUICtrlCreateTreeView(200,10,150,100,BitOr($TVS_CHECKBOXES,$TVS_SHOWSELALWAYS),$WS_EX_CLIENTEDGE)
Global $tvitem1     = GUICtrlCreateTreeViewItem("Item1",$treeview)
Global $tvitem2     = GUICtrlCreateTreeViewItem("Item2",$treeview)

GUICtrlSetState($tvitem2, $GUI_CHECKED); Does work for treeview.

Global $buttoncheck = GUICtrlCreateButton("CheckRead",100,250,70,20);
Global $buttontree  = GUICtrlCreateButton("TreeRead",220,250,70,20);
Global $buttonmenu  = GUICtrlCreateButton("MenuRead",10,250,70,20);

Global $checkbox    = GUICtrlCreateCheckbox("Check it",50,150,100,20)

Global $modecheck   = GUICtrlCreateCheckbox("Advanced Mode",200,150,100,20,$BS_PUSHLIKE);
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $lvitem1
            Msgbox(0,"",GUICtrlRead($lvitem1))
            
        Case $msg = $lvitem2
            $result = GUICtrlRead($lvitem2,1)
            If IsArray($result) Then
                Msgbox(0,"",$result[0] & @LF & $result[1])
            EndIf
            
        Case $msg = $tvitem1
            Msgbox(0,"",GUICtrlRead($tvitem1))
            
        Case $msg = $tvitem2
            $result = GUICtrlRead($tvitem2,1)
            If IsArray($result) Then
                Msgbox(0,"",$result[0] & @LF & $result[1])
            EndIf
        
        Case $msg = $buttonmenu
            CtrlInfo($menu1)
            
        Case $msg = $buttoncheck
            CtrlInfo($checkbox)
            
        Case $msg = $buttontree
            CtrlInfo($treeview)
    EndSelect
WEnd

GUIDelete()
Exit

Func CtrlInfo($ctrlid)
    Local $ctrlid
    
    If GUICtrlRead($modecheck) = $GUI_CHECKED Then
        $result = GUICtrlRead($ctrlid,1)
    Else
        $result = GUICtrlRead($ctrlid)
    EndIf
    If IsArray($result) Then
        Msgbox(0,"Read",$result[0] & @LF & $result[1])
    Else
        Msgbox(0,"Read",$result)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
Holger

@spytek: not implemented yet -> I knew I did forget something :D

Will try something out now...

Regards

Holger

Edit: got it so far - works OK...

So I will send it later to jpm :)

Edited by Holger

Share this post


Link to post
Share on other sites
spytek_98

@spytek: not implemented yet -> I knew I did forget something :D

Will try something out now...

Regards

Holger

Edit: got it so far - works OK...

So I will send it later to jpm :)

<{POST_SNAPBACK}>

Thanks Holger!

Look forward in seeing it implemented.

Edited by spytek_98

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.