Skip to content

DevExpress-Examples/winforms-grid-crud-operations-odata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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