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
- MainForm.cs (VB: MainForm.vb)
- WebApiConfig.cs (VB: WebApiConfig.vb)
- CustomersController.cs (VB: CustomersController.vb)
- OrdersController.cs (VB: OrdersController.vb)
- Customer.cs (VB: Customer.vb)
- DataContext.cs (VB: DataContext.vb)
- Order.cs (VB: Order.vb)
(you will be redirected to DevExpress.com to submit your response)