Programmatically edit a treeview label: Difference between revisions
→Getting it to work: added vdf source tags |
Hsymington (talk | contribs) m Added to Tutorials category |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 42: | Line 42: | ||
Correct syntax would be | Correct syntax would be | ||
<source lang="vdf"> | |||
Procedure AddAndEditItem | Procedure AddAndEditItem | ||
Handle hItem | Handle hItem | ||
Line 54: | Line 55: | ||
End | End | ||
End_Procedure | End_Procedure | ||
</source> | |||
Depending on the version of VDF you are using you have the following events and | Depending on the version of VDF you are using you have the following events and | ||
properties | properties | ||
<source lang="vdf"> | |||
pbCancelEdit | pbCancelEdit | ||
OnBeginLabelEdit | OnBeginLabelEdit | ||
OnEndLabelEdit | OnEndLabelEdit | ||
</source> | |||
These are documented in the Help system | These are documented in the Help system | ||
Line 69: | Line 73: | ||
[http://msdn.microsoft.com/en-us/library/bb773562(VS.85).aspx MSDN TVM_EDITLABEL Message] | [http://msdn.microsoft.com/en-us/library/bb773562(VS.85).aspx MSDN TVM_EDITLABEL Message] | ||
[[Category:How To]] | |||
[[Category:Tutorials]] |
Latest revision as of 11:46, 25 March 2020
The problem
The normal treeview class does not have a method of putting your treeview item into "edit mode" programmatically. Of course you can do this in the treeview when you are using it, but sometimes you have a need to set this state without requiring user interaction.
As if is a standard windows control, you can send it windows messages yourself. The message to send is TVM_EDITLABEL
Getting it to work
First you have to enable label editing with:
Set TreeEditLabelsState to True
Then you have to send TVM_EDITLABEL for example as in:
Procedure EditNow Handle hItem Handle hWnd Integer iResult Get CurrentTreeItem to hItem Get Window_Handle to hWnd Move (SendMessage(hWnd,TVM_EDITLABEL,0,hItem)) to iResult End_Procedure On_Key Key_Alt+Key_F1 Send EditNow
As you can see I've not tested with doing it just after adding the item but in the moment that the control is waiting for user action. Normally the F2 is used so you might replace Alt+F1 with the F2 key, I did not do this to see if my code was really used instead of build in techniques.
Enable editmode on a new item
First, you need the Window_Handle of the control you want to send the message to. This means you can send this message ONLY when the controls is paged. Second, you need the handle of the treeviewitem to edit. Third, the property TreeEditLabelState is a treeview property and not for the item.
Correct syntax would be
Procedure AddAndEditItem Handle hItem Get AddTreeItem of oTreeView1 "New item" 0 0 0 0 To hItem Set ItemData of oTreeView1 Item hItem to 999 Get Window_Handle of oTreeView1 to hWnd If (hWnd <> 0) Begin Set TreeEditLabelsState of oTreeView1 to True Move (SendMessage(hWnd,TVM_EDITLABEL,0,hItem)) to iResult Set TreeEditLabelsState of oTreeView1 to False End End_Procedure
Depending on the version of VDF you are using you have the following events and properties
pbCancelEdit OnBeginLabelEdit OnEndLabelEdit
These are documented in the Help system
External references
Automatic Edit item label in Treeview