BeforeLabelEdit occurs when a user attempts to edit the label of the currently selected ListItem or Node object. AfterLabelEdit occurs after a user edits the label of the currently selected Node or ListItem object.
Sub object_AfterLabelEdit(Cancel?, NewString As Variant)
Sub object_BeforeLabelEdit(Cancel?)
object:ListView, TreeView
Both the AfterLabelEdit and the BeforeLabelEdit events are generated only if the LabelEdit property is set to 0 (Automatic), or if the StartLabelEdit method is invoked.
The BeforeLabelEdit event occurs after the standard Click event.
To begin editing a label, the user must first click the object to select it, and click it a second time to begin the operation. The BeforeLabelEdit event occurs after the second click. To determine which object's label is being edited, use the SelectedItem property.
The AfterLabelEdit event is generated after the user finishes the editing operation, which occurs when the user clicks on another Node or ListItem or presses the ENTER key.
To cancel a label editing operation, set cancel to any nonzero number or to True. If a label editing operation is canceled, the previously existing label is restored.
The newstring argument can be used to test for a condition before canceling an operation. The newstring Variant is Null if the user canceled the operation.
Ocx TreeView tv = "", 10, 10, 100, 200
tv.Add , , , "Fred"
tv.Add , , , "Harry"
tv.Add , , , "Archie"
Do : Sleep : Until Me Is Nothing
Sub tv_BeforeLabelEdit(Cancel?)
If tv.SelectedItem.Index = 1 Then
MsgBox("This node cannot be edited")
Cancel = True ' Cancel the operation
End If
EndSub
Sub tv_AfterLabelEdit(Cancel?, NewString As Variant)
If IsNumeric(NewString) Then
MsgBox "No numbers allowed"
Cancel = True
End If
EndSub
The code checks the index of a selected Node before allowing an edit. If the index is 1, the operation is cancelled. Then the edit is cancelled when if newstring is a number.
ListView, TreeView, LabelEdit, StartLabelEdit
{Created by Sjouke Hamstra; Last updated: 24/09/2014 by James Gaite}