Jump to content

Right Click on a TreeView Item to get a "menu"


 Share

Recommended Posts

i believe there's no support for the SysTreeView in AutoIt at the moment

anyone else can verify?

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

Hello !

Can anyone please inform how to code, the function to be able to right click on a TreeViewItem, and get a menu,for example to Edit, Delete, Rename......

/Sven

You should be able to create a context menu for the treeview and then modify the code from the link in my signature for editable treeview item

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thank you, it works fine, but I don't know if I have coded right, but I have to left click on the item first, before making a right click and then choose from my menu.

Is this the right behaviour in AutoIT ?

Regards

Sven

I believe that's the behaviour of the control

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thank you, it works fine, but I don't know if I have coded right, but I have to left click on the item first, before making a right click and then choose from my menu.

Is this the right behaviour in AutoIT ?

Regards

Sven

The behavior is that with the right mouse click the item is checked and the context menu is shown, which make sense to me. See attached script direct from the help file with context menu added.

HTH, Reinhard

#include <GUIConstants.au3>

GUICreate("My GUI with treeview", 350, 212)

$treeview       = GUICtrlCreateTreeView(6, 6, 100, 150, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$generalitem    = GUICtrlCreateTreeViewitem("General", $treeview)
$displayitem    = GUICtrlCreateTreeViewitem("Display", $treeview)
$aboutitem      = GUICtrlCreateTreeViewitem("About", $generalitem)
$compitem       = GUICtrlCreateTreeViewitem("Computer", $generalitem)
$useritem       = GUICtrlCreateTreeViewitem("User", $generalitem)
$resitem        = GUICtrlCreateTreeViewitem("Resolution", $displayitem)
$otheritem      = GUICtrlCreateTreeViewitem("Other", $displayitem)
    $TvContext = GUICtrlCreateContextMenu($treeview)
    $TvHello = GUICtrlCreateMenuitem("Say Hello",$TvContext)
$startlabel     = GUICtrlCreateLabel("TreeView Demo",190,90,100,20)
$aboutlabel     = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
GUICtrlSetState(-1, $GUI_HIDE); Hides the "aboutlabel"-text during initialization
$compinfo       = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
GUICtrlSetState(-1, $GUI_HIDE); Hides the "compinfo"-text during initialization
$Status = GUICtrlCreateLabel("", 0, 302, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))


$okbutton       = GUICtrlCreateButton("OK", 100, 185, 70, 20)
$cancelbutton   = GUICtrlCreateButton("Cancel", 180, 185, 70, 20)

GUISetState ()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE
            ExitLoop
        case $msg = $TvHello
             Msgbox(0,"","Hello")
        Case $msg = $okbutton
            $item = GUICtrlRead($treeview); Get the controlID of the current selected treeview item
            If $item = 0 Then
                MsgBox(64, "TreeView Demo", "No item currently selected")
            Else
                $advmsg = GUICtrlRead($item, 1); Get advanced infos about the treeview item
                If ($advmsg[0] == 0) Then
                    MsgBox(16, "Error", "Error while retrieving infos about item")
                Else
                    MsgBox(64, "TreeView Demo", "Current item selected is: " & $advmsg[0]); $advmsg[0] contains the text and $advmsg[1] the state value of the treeview item
                EndIf
            EndIf
            
; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter)
        Case $msg = $generalitem
            GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel)
        
        Case $msg = $aboutitem
            GUICtrlSetState ($compinfo, $GUI_HIDE)
            GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel)
            
        Case $msg = $compitem
            GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo)
    EndSelect
WEnd

GUIDelete()
Exit

Func GUIChangeItems($hidestart, $hideend, $showstart, $showend)
    Local $idx
    
    For $idx = $hidestart To $hideend
        GUICtrlSetState ($idx, $GUI_HIDE)
    Next
    For $idx = $showstart To $showend
        GUICtrlSetState ($idx, $GUI_SHOW)
    Next    
EndFunc
Edited by ReFran
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...