How to keep the user from leaving a node in edit mode until they have entered a valid node name in WinForms TreeViewAdv?
NodeEditorValidating event
This can be done by handling the TreeViewAdv's NodeEditorValidating event as shown below:
C#
private void treeViewAdv1_NodeEditorValidating_1(object sender, TreeNodeAdvCancelableEditEventArgs e)
{
if (e.Label == "Syncfusion")
{
e.Cancel = false;
MessageBox.Show("Valid");
e.ContinueEditing = false;
}
else
{
// Cancel the label edit action, inform the user, and place the node in edit mode again
e.Cancel = true;
MessageBox.Show("Invalid name");
// To continue editing mode
e.ContinueEditing = true;
}
}VB
Private Sub treeViewAdv1_NodeEditorValidating_1(ByVal sender As Object, ByVal e As TreeNodeAdvCancelableEditEventArgs)
If e.Label = "Syncfusion" Then
e.Cancel = False
MessageBox.Show("Valid")
e.ContinueEditing = False
Else
' Cancel the label edit action, inform the user, and place the node in edit mode again.
e.Cancel = True
MessageBox.Show("Invalid name")
' To continue editing mode
e.ContinueEditing = True
End If
End Sub