mobilecontrols-devexpress-dot-xamarinforms-dot-datagrid-dot-editformpage.md
Occurs after a user changes a cell value in the default edit form and moves focus from the editor.
Namespace : DevExpress.XamarinForms.DataGrid
Assembly : DevExpress.XamarinForms.Grid.dll
NuGet Package : DevExpress.XamarinForms.Grid
public event DataGridValidationEventHandler ValidateCell
The ValidateCell event's data class is DataGridValidationEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| ErrorContent | Gets or sets the validation error description. |
| FieldName | Gets the field name of the column that contains the cell whose value is being edited. |
| Item | Gets an object that specifies a data source record to which the grid’s row containing the currently edited cell corresponds. |
| NewValue | Gets the editor’s value. |
| OldValue | Gets the cell’s value before editing is started. |
| RowHandle | Gets the handle of the row that contains the cell whose value is being edited. |
This example shows how to validate cell values that users enter in the edit form.
You can verify each value after a user modifies it (in the default edit form only) or validate the entire form (default or custom) when a user closes it.
Use the EditFormPage.ValidateCell event that occurs after a user changes a cell value in the default edit form and moves focus from the editor.
In the event hander:
<dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}"
Tap="Grid_Tap">
<!-- ... -->
</dxg:DataGridView>
using System;
using Xamarin.Forms;
using DevExpress.XamarinForms.DataGrid;
// ...
private void Grid_Tap(object sender, DataGridGestureEventArgs e) {
if (e.Item != null) {
var editForm = new EditFormPage(grid, grid.GetItem(e.RowHandle));
editForm.ValidateCell += EditForm_ValidateCell;
Navigation.PushAsync(editForm);
}
}
private void EditForm_ValidateCell(object sender, DataGridValidationEventArgs e) {
if (e.FieldName == "Quantity" && (decimal)e.NewValue <= 0) {
e.ErrorContent = "The value must be positive.";
}
else if (e.FieldName == "Date" && (DateTime)e.NewValue > DateTime.Now.Date)
e.ErrorContent = "The date value cannot be in the future.";
}
Use the EditFormPage.ValidateForm event that occurs after a user changes the values and tries to close the edit form.
In the event hander:
<dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}"
Tap="Grid_Tap">
<!-- ... -->
</dxg:DataGridView>
using System;
using Xamarin.Forms;
using DevExpress.XamarinForms.DataGrid;
// ...
private void Grid_Tap(object sender, DataGridGestureEventArgs e) {
if (e.Item != null) {
var editForm = new EditFormPage(grid, grid.GetItem(e.RowHandle));
editForm.ValidateForm += EditForm_ValidateForm;
Navigation.PushAsync(editForm);
}
}
private void EditForm_ValidateForm(object sender, EditFormValidationEventArgs e) {
if ((decimal)e.Values["Quantity"] <= 0) {
e.Errors.Add("Quantity", "The value must be positive.");
}
if ((DateTime)e.Values["Date"] > DateTime.Now.Date)
e.Errors.Add("Date", "The date value cannot be in the future.");
}
See Also