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?
Thanks
TreeView: enter edit mode (F2)
Re: TreeView: enter edit mode (F2)
Not sure what you're asking.
Re: TreeView: enter edit mode (F2)
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
like set styleEx or something...
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}
}
Re: TreeView: enter edit mode (F2)
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.
Re: TreeView: enter edit mode (F2)
How so? I tried something like that but no success.
Re: TreeView: enter edit mode (F2)
Check back tomorrow aftern and I'll reply. No computer access at the moment to make an example.
Re: TreeView: enter edit mode (F2)
ok. I'll. Thanks gilli!
Re: TreeView: enter edit mode (F2)
I tried this
but it didn't work
Code: Select all
Gui, Add, TreeView, gTreeViewHandle AltSubmit -ReadOnly hwndHTV
; ...
SendMessage, 0x110E, % A_ThisMenuItem, ahk_id %HTV%
Re: TreeView: enter edit mode (F2)
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.
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.
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
Re: TreeView: enter edit mode (F2)
Thanks anyway gilli.
Re: TreeView: enter edit mode (F2)
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