BeforeLabelEdit Event (ListView, TreeView Controls)

           

Occurs when a user attempts to edit the label of the currently selected ListItem or Node object.

Syntax

Private Sub object_BeforeLabelEdit(cancel As Integer)

The BeforeLabelEdit event syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
cancel An integer that determines if the operation is canceled. Any nonzero integer cancels the operation. The default is 0.

Remarks

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 following example checks the index of a selected Node before allowing an edit. If the index is 1, the operation is cancelled.

Private Sub TreeView1_BeforeLabelEdit(Cancel As Integer)
   If TreeView1.SelectedItem.Index = 1 Then
      Cancel = True   ' Cancel the operation
   End If
End Sub