Skip to main content
A newer version of this page is available. .
All docs
V21.2

DocumentPreviewControl.ValidateEditingField Event

Occurs before the editor invoked for the edit field is closed. Allows you to validate the edit field value.

Namespace: DevExpress.Xpf.Printing

Assembly: DevExpress.Xpf.Printing.v21.2.dll

NuGet Package: DevExpress.Wpf.Printing

Declaration

public event ValidateEditingFieldEventHandler ValidateEditingField

Event Data

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

Property Description
EditingField Gets the edit field for which the event is raised. Inherited from EditingFieldEditorEventArgsBase.
ErrorMessage Specifies the tooltip message.
ErrorType Specifies the type of the error icon displayed in the editor.
Handled Gets 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.
IsValid Specifies whether the edit field value is valid.
OriginalSource Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEvent Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
Source Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.
Value Gets the edit field value.

The event data class exposes the following methods:

Method Description
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.

Remarks

The following code validates the value in the edit field’s Date Time Editor so that the user can enter only dates for the current month:

<Window x:Class="ValidateEditingFields_MVVM.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:ValidateEditingFields_MVVM"
        xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing"
        xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
        Title="MainWindow" Height="450" Width="800">
    <Window.DataContext>
        <local:ViewModel />
    </Window.DataContext>
    <Grid>
        <dxp:DocumentPreviewControl RequestDocumentCreation="True"
                                    DocumentSource="{Binding Report}"
                                    HighlightEditingFields="True">
            <dxmvvm:Interaction.Behaviors>
                <dxmvvm:EventToCommand Event="{x:Static dxp:DocumentPreviewControl.ValidateEditingFieldEvent}"
                                       PassEventArgsToCommand="True"
                                       Command="{Binding OnValidateEditingFieldCommand}" />
            </dxmvvm:Interaction.Behaviors>
        </dxp:DocumentPreviewControl>
    </Grid>
</Window>
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Xpf.Printing;
using DevExpress.XtraReports.UI;
using System;

namespace ValidateEditingFields_MVVM {
    public class ViewModel : ViewModelBase {
        public XtraReport Report { get; }
        public ViewModel() {
            Report = new XtraReport1();
        }
        [Command]
        public void OnValidateEditingField(EditingFieldValidationEventArgs args) {
            if(args.EditingField.ID == "DateField")
                ValidateDateTimeEditingField(args);
        }

        void ValidateDateTimeEditingField(EditingFieldValidationEventArgs args) {
            DateTime value = default(DateTime);
            try {
                value = Convert.ToDateTime(args.Value);
            } catch (Exception e) {
                args.IsValid = false;
                args.ErrorMessage = e.Message;
                args.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical;
            }

            DateTime now = DateTime.Now;
            args.IsValid = value.Year == now.Year && value.Month == now.Month;
        }
    }
}

View Example: How to Validate the Editing Field Value in the Document Preview

See Also