Programmatically edit a treeview label: Difference between revisions
Hsymington (talk | contribs) m Added to Tutorials category |
|||
(6 intermediate revisions by 3 users not shown) | |||
Line 9: | Line 9: | ||
First you have to enable label editing with: | First you have to enable label editing with: | ||
<source lang="vdf"> | |||
Set TreeEditLabelsState to True | Set TreeEditLabelsState to True | ||
</source> | |||
Then you have to send TVM_EDITLABEL for example as in: | |||
<source lang="vdf"> | |||
Procedure EditNow | Procedure EditNow | ||
Handle hItem | Handle hItem | ||
Handle hWnd | Handle hWnd | ||
Integer iResult | Integer iResult | ||
Get CurrentTreeItem to hItem | Get CurrentTreeItem to hItem | ||
Get Window_Handle to hWnd | Get Window_Handle to hWnd | ||
Line 24: | Line 26: | ||
On_Key Key_Alt+Key_F1 Send EditNow | On_Key Key_Alt+Key_F1 Send EditNow | ||
</source> | |||
As you can see I've not tested with doing it just after adding the item but | As you can see I've not tested with doing it just after adding the item but | ||
Line 39: | Line 42: | ||
Correct syntax would be | Correct syntax would be | ||
Procedure | <source lang="vdf"> | ||
Procedure AddAndEditItem | |||
Handle hItem | Handle hItem | ||
Get AddTreeItem of oTreeView1 "New item" 0 0 0 0 To hItem | Get AddTreeItem of oTreeView1 "New item" 0 0 0 0 To hItem | ||
Set ItemData of oTreeView1 Item hItem to 999 | Set ItemData of oTreeView1 Item hItem to 999 | ||
Get Window_Handle of oTreeView1 to hWnd | Get Window_Handle of oTreeView1 to hWnd | ||
If (hWnd <> 0) Begin | If (hWnd <> 0) Begin | ||
Line 51: | 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 66: | 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