windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-b066d3c8.md
Occurs after changes made to a focused data row have been saved to an underlying data source.
Namespace : DevExpress.XtraGrid.Views.Base
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DXCategory("Action")]
public event RowObjectEventHandler RowUpdated
<DXCategory("Action")>
Public Event RowUpdated As RowObjectEventHandler
The RowUpdated event's data class is RowObjectEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Row | Gets the processed row. |
| RowHandle | Gets the row’s handle (position). For the ColumnView.RowUpdated event, this property specifies the previous handle (position) of the currently processed row. NewItemRowHandle value when a new row is added. Inherited from RowEventArgs. |
The RowUpdated event handler is the recommended place to post data to a data storage.
private void gridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) {
if (e.RowHandle == GridControl.NewItemRowHandle) {
// Create a new record.
} else {
// Update the corresponding record in a database.
}
}
Private Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowObjectEventArgs)
If e.RowHandle = GridControl.NewItemRowHandle Then
' Create a new record.
Else
' Update the corresponding record in a database.
End If
End Sub
The following example shows how to push row edits to an Entity Framework source.
DXApplication.AdventureWorksDW2008R2Entities dbContext;
private void gridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) {
dbContext.SaveChanges();
}
Private dbContext As DXApplication.AdventureWorksDW2008R2Entities
Private Sub gridView1_RowUpdated(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowObjectEventArgs)
dbContext.SaveChanges()
End Sub
This event fires only after the edited row has lost focus, i.e after a user has selected another row or clicked anywhere outside the View. The following example calls the the ColumnView.UpdateCurrentRow method to manually trigger the RowUpdated event as soon as a column CalcEdit in-place editor closes.
private void repositoryItemCalcEdit1_EditValueChanged(object sender, EventArgs e) {
gridView1.PostEditor(); //save the cell value to a data source
gridView1.UpdateCurrentRow(); //update the row and raise the RowUpdated event
}
Private Sub repositoryItemCalcEdit1_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
gridView1.PostEditor() 'save the cell value to a data source
gridView1.UpdateCurrentRow() 'update the row and raise the RowUpdated event
End Sub
Do not assign a new data source in the event handler. Use the Row parameter to obtain the data row.
private void GridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) {
DataRowView rowView = e.Row as DataRowView;
DataRow row = rowView.Row;
}
Private Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowObjectEventArgs)
Dim rowView As DataRowView = TryCast(e.Row, DataRowView)
Dim row As DataRow = rowView.Row
End Sub
To validate cell values before they are saved to a data source, handle the ColumnView.ValidateRow event.
Note
By default, if an exception is raised within a RowUpdated event handler, it is silently swallowed by the grid control. To prevent exceptions from being caught internally by the grid control, you can set the static DevExpress.Data.DataControllerBase.CatchRowUpdatedExceptions property to false on the application startup.
See Also