Back to Devexpress

ColumnView.RowUpdated Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-b066d3c8.md

latest5.5 KB
Original Source

ColumnView.RowUpdated Event

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

Declaration

csharp
[DXCategory("Action")]
public event RowObjectEventHandler RowUpdated
vb
<DXCategory("Action")>
Public Event RowUpdated As RowObjectEventHandler

Event Data

The RowUpdated event's data class is RowObjectEventArgs. The following properties provide information specific to this event:

PropertyDescription
RowGets the processed row.
RowHandleGets 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.

Remarks

The RowUpdated event handler is the recommended place to post data to a data storage.

csharp
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.
    }
}
vb
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.

csharp
DXApplication.AdventureWorksDW2008R2Entities dbContext;

private void gridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) {
    dbContext.SaveChanges();
}
vb
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.

csharp
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
}
vb
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.

csharp
private void GridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) {
    DataRowView rowView = e.Row as DataRowView;
    DataRow row = rowView.Row;
}
vb
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

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace