Sign in to follow this  
Followers 0
paulerino

treeview with contextMenu on each item

4 posts in this topic

Hi

I am new to Autoit and I try to construct a treeview so that each item is bound to a contextMenu (the same for all items).

I would be pleased if somebody could show me a sample code ...

Thank's

Paul

Share this post


Link to post
Share on other sites



Something like this:

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

$gui = GUICreate("Test", 200, 200)
$tree = GUICtrlCreateTreeView(10, 10, 100, 150, -1, $WS_EX_CLIENTEDGE)
$all = GUICtrlCreateTreeViewItem("All", $tree)

GUISetState()

While 1
    $msg = GUIGetMsg()
    
    Select
        
    Case $msg = -3
        ExitLoop
        
    Case $msg = $GUI_EVENT_SECONDARYUP
        $CurPos = GUIGetCursorInfo($gui)
        If $CurPos[4] = $tree And _GUICtrlTreeViewGetState($tree, $all) = 2 Then MsgBox(0, "", "Selected")
    
    EndSelect
WEnd

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites

Hi, a working context menu per treeview item

#include <GUIConstants.au3>

Global $TVItem[11][3], $cnt = 1

$Gui = GUICreate("Treeview Context Menu", 250, 200)
$treeview = GUICtrlCreateTreeView(0, 0, 250, 200)
For $i = 1 To 5
    $TVItem[$cnt][0] = GUICtrlCreateTreeViewitem("Parent Item " & $i, $treeview)
    $TVItem[$cnt][1] = GUICtrlCreateContextMenu($TVItem[$cnt][0])
    $TVItem[$cnt][2] = GUICtrlCreateMenuItem("Rename " & GuiCtrlRead($TVItem[$cnt][0], 1), $TVItem[$cnt][1])
    $cnt += 1
    $TVItem[$cnt][0] = GUICtrlCreateTreeViewitem("Parent " & $i & " Child Item 1", $TVItem[$cnt-1][0])
    $TVItem[$cnt][1] = GUICtrlCreateContextMenu($TVItem[$cnt][0])
    $TVItem[$cnt][2] = GUICtrlCreateMenuItem("Rename " & GuiCtrlRead($TVItem[$cnt][0], 1), $TVItem[$cnt][1])
    $cnt += 1
Next    

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $TVItem[1][2]
            Rename($TVItem[1][2], $TVItem[1][0])
        Case $TVItem[2][2]  
            Rename($TVItem[2][2], $TVItem[2][0])
        Case $TVItem[3][2]  
            Rename($TVItem[3][2], $TVItem[3][0])
        Case $TVItem[4][2]  
            Rename($TVItem[4][2], $TVItem[4][0])
        Case $TVItem[5][2]  
            Rename($TVItem[5][2], $TVItem[5][0])
        Case $TVItem[6][2]  
            Rename($TVItem[6][2], $TVItem[6][0])
        Case $TVItem[7][2]  
            Rename($TVItem[7][2], $TVItem[7][0])
        Case $TVItem[8][2]  
            Rename($TVItem[8][2], $TVItem[8][0])
        Case $TVItem[9][2]  
            Rename($TVItem[9][2], $TVItem[9][0])
        Case $TVItem[10][2] 
            Rename($TVItem[10][2], $TVItem[10][0])          
    EndSwitch       
WEnd

Func Rename($CTVID, $ITVID)
    $Input = InputBox("Rename TreeView Item", "Enter a new name", GUICtrlRead($ITVID, 1), "", 200, 120)
    If $Input <> "" Then
        GUICtrlSetData($CTVID, "Rename " & $Input)
        GUICtrlSetData($ITVID, $Input)
    EndIf   
EndFunc

Cheers

Share this post


Link to post
Share on other sites

ok

cool, thank's very much

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