maui-devexpress-dot-maui-dot-datagrid-dot-datagridview-849a825c.md
Occurs after a user changes a cell value in the in-place editor and attempts to select another cell.
Namespace : DevExpress.Maui.DataGrid
Assembly : DevExpress.Maui.DataGrid.dll
NuGet Package : DevExpress.Maui.DataGrid
public event EventHandler<ValidateCellEventArgs> ValidateCell
The ValidateCell event's data class is ValidateCellEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| ErrorContent | Gets or sets the validation error description. |
| FieldName | Returns the field name of the column that contains the cell whose value is being edited. |
| Item | Returns the data source object that is used to create the processed cell’s row. |
| NewValue | Returns the editor’s value. |
| OldValue | Returns the cell’s value before editing is started. |
| RowHandle | Returns the handle of the row that contains the cell whose value is being edited. |
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.ValidateCell event, and implement validation logic in the event handler.ErrorContent string is empty.ValidateCell event handler.<dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}"
ValidateCell="Grid_ValidateCell"
ValidationError="Grid_ValidationError">
<!-- ... -->
</dxg:DataGridView>
using Microsoft.Maui.Controls;
using DevExpress.Maui.DataGrid;
// ...
private void Grid_ValidateCell(object sender, ValidateCellEventArgs 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