Skip to content

Latest commit

 

History

History
64 lines (48 loc) · 3.9 KB

File metadata and controls

64 lines (48 loc) · 3.9 KB

WinForms Data Grid - CRUD operations (OData)

This example shows how to bind the WinForms Data Grid control to a BindingSource that gets data from OData services.

Unlike the Entity Framework data context, the OData service context does not have automatic change tracking (you must track changes manually). This example demonstrates how to handle grid events to track user edits.

Each time the user changes the value in a cell and commits the row, the GridView raises the RowUpdated event. Handle this event to notify the data context about the change. When a row has been deleted, the GridView raises the RowDeleted event.

private void GridView_RowUpdated(object sender, RowObjectEventArgs e) {
  if (e.RowHandle == GridControl.NewItemRowHandle) {
    this.Context.AddToOrders((Order)e.Row);
  } else {
    this.Context.UpdateObject(e.Row);
  }
}

private void GridView_RowDeleted(object sender, RowDeletedEventArgs e) {
  this.Context.DeleteObject(e.Row);
}
Private Sub GridView_RowUpdated(sender As Object, e As RowObjectEventArgs) Handles GridView1.RowUpdated
  If e.RowHandle = GridControl.NewItemRowHandle Then
    Me.Context.AddToOrders(CType(e.Row, Order))
    Else Me.Context.UpdateObject(e.Row)
  End If
End Sub

Private Sub GridView_RowDeleted(sender As Object, e As RowDeletedEventArgs) Handles GridView1.RowDeleted
  Me.Context.DeleteObject(e.Row)
End Sub

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)