Sign in to follow this  
Followers 0
James

Treeview - Right click menu

10 posts in this topic

Hi all,

Currently working on an INI file viewer/editor. I have all of the generating from INI done so now it displays like this:

FILENAME

Section1

Key1

Value1

Key2

Value2

Section2

Key 1

Value 1

Key 2

Value 2

Works well :D

Now, I need to know how to get a context menu on the right click of an item. I need to be able to edit the value of the item.

After that's all done, I can work on saving the tree into *.INI format :D

Thanks,

James

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Solved it :D Thanks to whoever made WM_NOTIFY()

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
   
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
   
    Switch $hWndFrom
    Case $hWndTreeview
        Switch $iCode
        Case $NM_RCLICK
            TreeView_RClick()
        EndSwitch
    EndSwitch
EndFunc

Func TreeView_RClick()
    Local $Hit, $MousePos, $hMenu
   
    $MousePos = MouseGetPos()
    $Hit = _GUICtrlTreeView_HitTestItem($hTreeView, $MousePos[0], $MousePos[1])
    If ($Hit <> 0) Then
       
        $hMenu = _GUICtrlMenu_CreatePopup()
        _GUICtrlMenu_AddMenuItem($hMenu, "Rename", $idMenuRename)
        _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idMenuDelete)
       
        Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hTreeView, -1, -1, 1, 1, 2)
            Case $idMenuRename
                ConsoleWrite("Rename" & @CRLF)
            Case $idMenuDelete
                $mConf = MsgBox(0x4+0x40, "InsideNI | INedisnI", "Are you sure you wish to remove:" & @CRLF & _GUICtrlTreeView_GetText($hTreeView, $Hit) & "?")
                If $mConf = 4 Then
                    _GUICtrlTreeView_Delete($hTreeView, $Hit)
                EndIf
        EndSwitch
        _GUICtrlMenu_DestroyMenu($hMenu)
    EndIf
EndFunc ;==>ListView_RClick

I found it somewhere along with TreeView_RClick() :D Thanks whoever made those functions.

How do I edit the text of a node now? I have tried to use _GUICtrlTreeView_EditText(), but it doesn't edit the text.

I found the right style for editing the nodes but the change doesn't stay how it should be. Let's say I have a nod, I edit it from 1 to 2 I click off and it changes back to 1.

Edited by JamesB

Share this post


Link to post
Share on other sites

How do I edit the text of a node now? I have tried to use _GUICtrlTreeView_EditText(), but it doesn't edit the text.

I found the right style for editing the nodes but the change doesn't stay how it should be. Let's say I have a nod, I edit it from 1 to 2 I click off and it changes back to 1.

After editing from 1 to 2 you must press Enter.

Share this post


Link to post
Share on other sites

I have tried that, it doesn't do anything. This is the style I am using:

Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)

Just an edited one from the helpfile.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

#include <GUIConstants.au3>
#include <GUITreeView.au3>

Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)

$GUI = GUICreate("", 266, 277, 371, 266)
$Tree = _GUICtrlTreeView_Create($GUI, 8, 8, 249, 265, $iStyle)
$Test1 = _GUICtrlTreeView_Add($Tree, 0, "Change me")
$Test2 = _GUICtrlTreeView_AddChild($Tree, $Test1, "Change me")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Pressing enter or clicking off does not work.

Even the helpfile example doesn't work.

Edited by JamesB

Share this post


Link to post
Share on other sites

I tried that but no success on WIN98

#include <GUIConstants.au3>
#include <GUITreeView.au3>

Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)

$GUI = GUICreate("", 266, 277, 371, 266)
$TreeId = GUICtrlCreateTreeView (8, 8, 249, 265, $iStyle)
;~ $Tree = GUICtrlGetHandle($TreeId)
$Test1 = GUICtrlCreateTreeViewitem("Change me", $TreeId)
$Test2 = GUICtrlCreateTreeViewitem("Change me", $Test1)

;~ $Tree = _GUICtrlTreeView_Create($GUI, 8, 8, 249, 265, $iStyle)
;~ $Test1 = _GUICtrlTreeView_Add($Tree, 0, "Change me")
;~ $Test2 = _GUICtrlTreeView_AddChild($Tree, $Test1, "Change me")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

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