I will show you how easy is to integrate OpenAccess with RadGridView for Silverlight. I get the example from my colleague Dimitur and make it work with our RadGridView. If you are interested how to make OpenAccess to work with ADO.NET Data Services please read his blog series.

To allow inserting new rows in RadGridView we should attach to AddingNewDataItem event.

<telerik:RadGridView x:Name="gridView" Grid.Row="1" AddingNewDataItem="GridViewAddingNewDataItem" />

And provide the newly created object in it.

private void GridViewAddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
 e.NewObject = new Supplier();

Now we can insert new objects.

Next steps is to save changes to the database. We should attach to GridViewRow.EditEndedEvent.

this.gridView.AddHandler(GridViewRow.EditEndedEvent, new EventHandler<RecordRoutedEventArgs>(this.OnGridViewRowEditEnded));

This event occurs when the editing of the row ends. And this is our handler:

private void OnGridViewRowEditEnded(object sender, RecordRoutedEventArgs e)
    DataRecord record = (DataRecord)e.Record;
    Supplier supplier = (Supplier)record.Data;

    // if the record is disconnected we add the new item to the collection that we use as data source
    if (record.IsDisconnected)
        this.context.BeginSaveChanges(SaveChangesOptions.ContinueOnError, this.OnSaveAllComplete, null);
        this.context.BeginSaveChanges(SaveChangesOptions.ContinueOnError, this.OnSaveAllComplete, null);

We can have two states of our records. If it is disconnected this mean that the record is new and we should add it to the database. If it isn't we should update it to the database.


In this demo you can find also how to delete the current selected item.


Related Posts


Comments are disabled in preview mode.