wpf-devexpress-dot-xpf-dot-grid-dot-dataviewbase-e3c3ff7f.md
Gets or sets which type of errors the grid control should detect.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public ErrorsWatchMode ErrorsWatchMode { get; set; }
Public Property ErrorsWatchMode As ErrorsWatchMode
| Type | Description |
|---|---|
| ErrorsWatchMode |
One of the ErrorsWatchMode enumeration values that is an error watch mode.
|
Available values:
| Name | Description |
|---|---|
| None |
Grid View does not detect errors during the initial data load.
| | Default |
The error watch mode is disabled by default for the master grid view; for the detail grid view, the error watch mode depends on the error watch mode for the master view.
| | Rows |
Grid View detects invalid rows.
| | Cells |
Grid View detects invalid cells.
| | All |
Grid View detects invalid rows and cells.
|
Use the ErrorsWatchMode property to make the GridControl detect errors in its data.
When the ErrorsWatchMode property is set to Rows or Cells , the GridControl detects invalid rows or cells respectively. When the ErrorsWatchMode property is set to All , both invalid rows and cells are detected.
To disable the errors watching mechanism, set the ErrorsWatchMode property to None.
Note
When the ErrorsWatchMode property is set to All , Cell , or Row , the GridControl revalidates its data during the initial loading that can significantly decrease the control’s performance.
To pass validation data from the GridControl to a view model, use the ReadOnlyDependencyPropertyBindingBehavior to bind the view’s HasErrors property to a view model property. Set the view’s ErrorsWatchMode property to Cells.
<dx:ThemedWindow x:Class="DXSample.MainWindow"
Title="{DXBinding '`GridControl has errors: ` + HasErrors'}">
<dx:ThemedWindow.DataContext>
<local:MainViewModel />
</dx:ThemedWindow.DataContext>
<DockPanel>
<dxg:GridControl AutoGenerateColumns="AddNew"
ItemsSource="{Binding TaskList}">
<dxg:GridControl.View>
<dxg:TableView ErrorsWatchMode="Cells"
InvalidRowExceptionCommand="{Binding InvalidRowCommand}"
ValidateRowCommand="{Binding ValidateRowCommand}">
<dxmvvm:Interaction.Behaviors>
<dxmvvm:ReadOnlyDependencyPropertyBindingBehavior Property="HasErrors"
Binding="{Binding HasErrors, UpdateSourceTrigger=PropertyChanged}" />
</dxmvvm:Interaction.Behaviors>
</dxg:TableView>
</dxg:GridControl.View>
</dxg:GridControl>
</DockPanel>
</dx:ThemedWindow>
public class MainViewModel : ViewModelBase {
public bool HasErrors {
get { return GetValue<bool>(); }
set { SetValue(value); }
}
public ObservableCollection<Task> TaskList { get; }
public MainViewModel() {
TaskList = new ObservableCollection<Task> {
new Task() {
TaskName = "Complete Project A",
StartDate = new DateTime(2009, 7, 17),
EndDate = new DateTime(2009, 7, 10)
},
new Task() {
TaskName = "Test Website",
StartDate = new DateTime(2009, 7, 10),
EndDate = new DateTime(2009, 7, 12)
},
new Task() {
TaskName = string.Empty,
StartDate = new DateTime(2009, 7, 4),
EndDate = new DateTime(2009, 7, 6)
}
};
}
[Command]
public void ValidateRow(RowValidationArgs args) {
args.Result = GetValidationErrorInfo((Task)args.Item);
}
static ValidationErrorInfo GetValidationErrorInfo(Task task) {
if (task.StartDate > task.EndDate)
return new ValidationErrorInfo("Start Date must be less than End Date");
if (string.IsNullOrEmpty(task.TaskName))
return new ValidationErrorInfo("Enter a task name");
return null;
}
[Command]
public void InvalidRow(InvalidRowExceptionArgs args) {
args.ExceptionMode = ExceptionMode.NoAction;
}
}
Public Class MainViewModel
Inherits ViewModelBase
Public Property HasErrors As Boolean
Get
Return GetValue(Of Boolean)()
End Get
Set(ByVal value As Boolean)
SetValue(value)
End Set
End Property
Public ReadOnly Property TaskList As ObservableCollection(Of Task)
Public Sub New()
TaskList = New ObservableCollection(Of Task) From {New Task() With {.TaskName = "Complete Project A", .StartDate = New DateTime(2009, 7, 17), .EndDate = New DateTime(2009, 7, 10)}, New Task() With {.TaskName = "Test Website", .StartDate = New DateTime(2009, 7, 10), .EndDate = New DateTime(2009, 7, 12)}, New Task() With {.TaskName = String.Empty, .StartDate = New DateTime(2009, 7, 4), .EndDate = New DateTime(2009, 7, 6)}}
End Sub
<Command>
Public Sub ValidateRow(ByVal args As RowValidationArgs)
args.Result = GetValidationErrorInfo(CType(args.Item, Task))
End Sub
Private Shared Function GetValidationErrorInfo(ByVal task As Task) As ValidationErrorInfo
If task.StartDate > task.EndDate Then Return New ValidationErrorInfo("Start Date must be less than End Date")
If String.IsNullOrEmpty(task.TaskName) Then Return New ValidationErrorInfo("Enter a task name")
Return Nothing
End Function
<Command>
Public Sub InvalidRow(ByVal args As InvalidRowExceptionArgs)
args.ExceptionMode = ExceptionMode.NoAction
End Sub
End Class
See Also