Back to Devexpress

TreeViewControl.ValidateNode Event

wpf-devexpress-dot-xpf-dot-grid-dot-treeviewcontrol-784caff6.md

latest7.9 KB
Original Source

TreeViewControl.ValidateNode Event

Allows you to validate the focused node’s data and specify whether to close the node’s editor.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public event TreeViewNodeValidationEventHandler ValidateNode
vb
Public Event ValidateNode As TreeViewNodeValidationEventHandler

Event Data

The ValidateNode event's data class is TreeViewNodeValidationEventArgs. The following properties provide information specific to this event:

PropertyDescription
CultureGets the culture related to the validation. Inherited from ValidationEventArgs.
ErrorContentGets or sets an object that describes the validation error. Inherited from ValidationEventArgs.
ErrorTypeGets or sets the error icon type. Inherited from ValidationEventArgs.
HandledGets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
IsValidGets or sets a value specifying whether the value is valid. Inherited from ValidationEventArgs.
NodeGets the processed node.
OriginalSourceGets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
RowHandleGets the processed node’s row handle.
SourceGets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.
TreeViewControlGets the TreeViewControl that raised this event.
UpdateSourceGets the action that caused the validation. Inherited from ValidationEventArgs.
ValueGets the editor’s value. Inherited from ValidationEventArgs.

The event data class exposes the following methods:

MethodDescription
InvokeEventHandler(Delegate, Object)When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object)When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.
SetError(Object, ErrorType)Marks the processed input value as invalid and displays an error within the editor with the specified error icon type. Inherited from ValidationEventArgs.
SetError(Object)Marks the processed input value as invalid and displays an error within the editor. Inherited from ValidationEventArgs.

Remarks

The TreeViewControl allows you to validate new node values. To enable this behavior, handle the ValidateNode event. This event occurs when a node is about to lose focus.

The Value property returns the focused node’s new value. To indicate that the new value is invalid, set the IsValid property to false.

Set the AllowLeaveInvalidEditor property to true to allow users to close an editor that did not pass validation.

Example

xaml
<dxg:TreeViewControl x:Name="treeview"
                     AllowEditing="True"
                     ValidateNode="treeview_ValidateNode"
                     ... />
csharp
void treeview_ValidateNode(object sender, DevExpress.Xpf.Grid.TreeList.TreeViewNodeValidationEventArgs e) {
    e.IsValid = (e.Value != null) && (e.Value.ToString().Length >= 5);
    e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning;
    e.ErrorContent = "The name must contain at least 5 characters.";
}
vb
Private Sub treeview_ValidateNode(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.TreeList.TreeViewNodeValidationEventArgs)
    e.IsValid = (e.Value IsNot Nothing) AndAlso (e.Value.ToString().Length >= 5)
    e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning
    e.ErrorContent = "The name must contain at least 5 characters."
End Sub

For more information, refer to the following help topic: Edit Data.

See Also

TreeViewControl Class

TreeViewControl Members

DevExpress.Xpf.Grid Namespace