TreeView: enter edit mode (F2)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Azevedo
Posts: 81
Joined: 07 Feb 2014, 11:35

TreeView: enter edit mode (F2)

30 Aug 2015, 14:12

Hi,

I have this TreeView with editing enabled -ReadOnly - which can be edited by pressing F2.

How do I set the selected TV item to enter in edit mode?
Image

Thanks
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: TreeView: enter edit mode (F2)

30 Aug 2015, 14:37

Not sure what you're asking.
Azevedo
Posts: 81
Joined: 07 Feb 2014, 11:35

Re: TreeView: enter edit mode (F2)

30 Aug 2015, 19:41

If you press F2 in a treeview you can edit the selected entry, right?

In the picture, I want to trigger that feature when the user clicks Rename in the context menu

there must be another way other than SendInput

Code: Select all

	TVContextHandler:
		if (A_ThisMenuItem == "Rename`tF2") {
			SendInput, {F2}
		}
like set styleEx or something...
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: TreeView: enter edit mode (F2)

30 Aug 2015, 21:45

I'd recommend a combination of TV_GetSelection() and TV_Modify() to replicate what you want. That way your not trying to Send F2, but actively modifying it properly like you want.
Azevedo
Posts: 81
Joined: 07 Feb 2014, 11:35

Re: TreeView: enter edit mode (F2)

30 Aug 2015, 21:49

How so? I tried something like that but no success.
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: TreeView: enter edit mode (F2)

30 Aug 2015, 22:28

Check back tomorrow aftern and I'll reply. No computer access at the moment to make an example.
Azevedo
Posts: 81
Joined: 07 Feb 2014, 11:35

Re: TreeView: enter edit mode (F2)

30 Aug 2015, 23:26

ok. I'll. Thanks gilli!
Azevedo
Posts: 81
Joined: 07 Feb 2014, 11:35

Re: TreeView: enter edit mode (F2)

31 Aug 2015, 11:25

I tried this

Code: Select all

Gui, Add, TreeView, gTreeViewHandle AltSubmit -ReadOnly hwndHTV

; ...

SendMessage, 0x110E, % A_ThisMenuItem,  ahk_id %HTV%
but it didn't work
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: TreeView: enter edit mode (F2)

31 Aug 2015, 13:45

In hindsight this may not work as cleanly as you're hoping for. I don't know how to generate the edit in the TV like hitting F2 does, however editing it is still simple.

Code: Select all

#SingleInstance, Force

Gui, Add, TreeView, -ReadOnly
P1 := TV_Add("First parent")
P1C1 := TV_Add("Parent 1's first child", P1)  ; Specify P1 to be this item's parent.
P2 := TV_Add("Second parent")
P2C1 := TV_Add("Parent 2's first child", P2)
P2C2 := TV_Add("Parent 2's second child", P2)
P2C2C1 := TV_Add("Child 2's first child", P2C2)

Gui, Show  ; Show the window and its TreeView.
return

GuiClose:  ; Exit the script when the user closes the TreeView's GUI window.
ExitApp

GuiContextMenu:
TV_Modify(A_EventInfo,,"New Name")
Return
This is from the example in the documentation, I just made it editable and added the GuiContextMenu subroutine. GuiContextMenu will automatically store the ID of the TV item that is right clicked into A_EventInfo. You can then use TV_MOdify to edit it's title. The simplest method I can think of is a tiny little edit GUI or an InputBox. But neither of those options give you clean looking edit IN the GUI like F2 does. Sending F2 might be your best bet.
Azevedo
Posts: 81
Joined: 07 Feb 2014, 11:35

Re: TreeView: enter edit mode (F2)

31 Aug 2015, 17:28

Thanks anyway gilli.
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: TreeView: enter edit mode (F2)

01 Sep 2015, 02:00

Code: Select all

#NoEnv
Menu, TVMenu, Add, Rename`tF2, TVMenuLabel
Gui, Add, TreeView, w400 r10 -Readonly hwndHTV vVTV
RootID := TV_Add("Root", 0, "Expand")
Loop, 9
   TV_Add("Child" . A_Index, RootID)
Gui, Show, , Test
Return

GuiClose:
ExitApp

GuiContextMenu:
If (A_GuiControl = "VTV") {
   ClickedID := A_EventInfo
   TV_Modify(ClickedID, "Select")
   Menu, TVMenu, Show
}
Return

TVMenuLabel:
   If (A_ThisMenuItemPos = 1)
      SendMessage, 0x110E, 0, ClickedID, , ahk_id %HTV%
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mapcarter, peter_ahk, Rohwedder and 312 guests