mobilecontrols-devexpress-dot-xamarinforms-dot-datagrid-dot-datagridview-0a12d89d.md
Occurs when a value in the in-place cell editor fails validation or when it cannot be saved to a data source.
Namespace : DevExpress.XamarinForms.DataGrid
Assembly : DevExpress.XamarinForms.Grid.dll
NuGet Package : DevExpress.XamarinForms.Grid
public event ValidationErrorEventHandler ValidationError
The ValidationError event's data class is ValidationErrorEventArgs. The following properties provide information specific to this event:
| Property |
|---|
| ErrorContent |
This example shows how to validate a new cell value when a user modified it in an in-place cell editor and moves focus to another cell.
The DataGridView instance is bound to a collection of orders, and its Quantity column allows users to enter positive numbers only. If a new cell value does not pass validation, an error message is displayed and the user cannot move focus to another cell until the error is corrected.
Follow the steps below to validate cell values:
DataGridView.ValidationError event to provide a response to entering invalid data (for example, show validation error message to users). This event parameter’s ValidationErrorEventArgs.ErrorContent property contains the error description assigned to the DataGridValidationEventArgs.ErrorContent property in the ValidateCell event hander.<dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}"
ValidateCell="Grid_ValidateCell"
ValidationError="Grid_ValidationError">
<!-- ... -->
</dxg:DataGridView>
using Xamarin.Forms;
using DevExpress.XamarinForms.DataGrid;
// ...
private void Grid_ValidateCell(object sender, DataGridValidationEventArgs e) {
if (e.FieldName == "Quantity" && (decimal)e.NewValue <= 0)
e.ErrorContent = "The value must be positive.";
}
private void Grid_ValidationError(object sender, ValidationErrorEventArgs e) {
DisplayAlert("Input Error", e.ErrorContent, "OK");
}
See Also