This is a migrated thread and some comments may be shown as answers.

RadGridView refresh/rebind after new row insertion?

3 Answers 386 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Adam L. Ooten
Top achievements
Rank 2
Adam L. Ooten asked on 15 Dec 2010, 09:23 PM

We are using the RadGridView for a Silverlight project (vb). We are populating  the grid through RIA services with the Microsoft entity data model. The grid is bound fine – the issue we’re having is after a row is inserted we can’t find out how to refresh/rebind the grid to display that new row. We can confirm that the newly inserted row is properly being added to the table with initial column values. However, nothing we have tried has allowed us to rebind the grid automatically after the insert to display that new row.  We bind with the following:

 

Dim objTimesheets = Me.mycontext.Load(mycontext.GetRCTimesheetsQuery) 
RadGridView1.ItemsSource = objTimesheets.Entities

 

We have tried calling this after the insert function (put this is in a LoadGrid sub). Also have tried calling RadGridView1.Rebind()

 

The following is how we set up the insert:

 

 

Private Sub RadGridView1_AddingNewDataItem(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs) Handles RadGridView1.AddingNewDataItem
        e.NewObject = New Web.RCTimesheet
    End Sub
  
    Private Sub RadGridView1_RowEditEnded(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.GridViewRowEditEndedEventArgs) Handles RadGridView1.RowEditEnded
        If e.EditAction = Telerik.Windows.Controls.GridView.GridViewEditAction.Cancel Then
            Return
        End If
  
        If e.EditOperationType = Telerik.Windows.Controls.GridView.GridViewEditOperationType.Edit Then
                mycontext.SubmitChanges()
End If
  
If e.EditOperationType = Telerik.Windows.Controls.GridView.GridViewEditOperationType.Insert Then
            Dim timesheetRow As New Web.RCTimesheet
            timesheetRow = e.NewData
            timesheetRow.RCEmployeeID = RCEmployeeID
            timesheetRow.RCPayPeriodID = RCPayperiodID
            timesheetRow.RCTimesheetTaskID = 0
            mycontext.RCTimesheets.Add(timesheetRow)
            mycontext.SubmitChanges()
        End If
  
    End Sub


This issue happens with using the insert key on the keyboard, and a button set up that calls the BeginInsert() method. Always the same result – the row is added without flaw to the data table, but we can’t get the client side control to reflect this change.

 

Also, hitting refresh on the browser (the only way we’ve been able to see newly inserted rows) seems to bug out a foreign key column binding we have set up. The values for all rows except the first will be blank until clicked on (where they will snap to the correct dropdown value).

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 16 Dec 2010, 11:02 AM
Hi Adam L. Ooten,

If you are subscribed to the LoadingNewDataItem event and you are setting the e.NewObject property there you need to add the same object to the domain context so it knows that there are changes and commit them in the RowEditEnded event.

Here is an example:

Private Sub gvCustomers_AddingNewDataItem(sender As Object, e As GridViewAddingNewEventArgs)
    Dim customer = New Customer() With { _
        .CompanyName = "AA test company", _
        .CustomerID = "AATTT" _
    }
 
    e.NewObject = customer
 
    Dim context As CustomersContext = TryCast(Me.customerDomainDataSource.DomainContext, CustomersContext)
    context.Customers.Add(customer)
End Sub


Private Sub gvCustomers_RowEditEnded(sender As Object, e As GridViewRowEditEndedEventArgs)
    If e.EditAction = GridViewEditAction.Commit Then
        customerDomainDataSource.SubmitChanges()
    End If
End Sub


Hope this helps.


Greetings,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Adam L. Ooten
Top achievements
Rank 2
answered on 16 Dec 2010, 09:36 PM

Did some reorganizing and tried the new code close as we could match it. Same issue – the row inserts into the database fine, is properly edited/changed, and is there on a refresh, but does not automatically get added to the display. Soon as you click off the insert row it’s gone until the page is reloaded.

 

Also, we are setting up the context a bit differently. We tried the TryCast block in your example, but couldn’t find the right properties. We did try dimming a completely new context too, but it had no success.

 

 At the top of our page we have:

 

Private mycontext As New RCDomainContext

Which we are using as save/load from.

 

Our functions look like this now:

 

Private Sub RadGridView1_AddingNewDataItem(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs) Handles RadGridView1.AddingNewDataItem
  
        Dim timesheetRow As New Web.RCTimesheet() With { _
            .RCEmployeeID = RCEmployeeID, _
            .RCPayPeriodID = RCPayperiodID, _
            .RCTimesheetTaskID = 0 _
        }
  
        e.NewObject = timesheetRow
  
        mycontext.RCTimesheets.Add(timesheetRow)
  
    End Sub
  
    Private Sub RadGridView1_RowEditEnded(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.GridViewRowEditEndedEventArgs) Handles RadGridView1.RowEditEnded
  
        If e.EditAction = GridView.GridViewEditAction.Commit Then
            mycontext.SubmitChanges()
        End If
    End Sub

0
Veselin Vasilev
Telerik team
answered on 21 Dec 2010, 04:45 PM
Hi Adam L. Ooten,

It seems to be working ok here.

If you still face the problem - can you please send us a sample project reproducing the issue?

Thanks

Kind regards,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Adam L. Ooten
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Adam L. Ooten
Top achievements
Rank 2
Share this question
or