Ok i am using Entity Framework to access my data, I have no problem adding a record or deleting a record. But when I want to update a record I cant figure out what events to capture.
I have tried adding a RadGridView1_RowsChanged to the code and it works great for the update, but my problem occurs now that when I add a record to the grid RadGridView1_RowsChanged gets called before RadGridView1_UserAddedRow.
In fact the NotifyCollectionChangedAction.ItemChanged gets called before NotifyCollectionChangedAction.Add gets called
So as soon as I leave a cell in the row my itemchanged fires before the add and i get problems.
How can i idenitfy if row is being added instead of updated. I sue wish there was a UserUpdatedRow event
Any help is appreciated
I have tried adding a RadGridView1_RowsChanged to the code and it works great for the update, but my problem occurs now that when I add a record to the grid RadGridView1_RowsChanged gets called before RadGridView1_UserAddedRow.
In fact the NotifyCollectionChangedAction.ItemChanged gets called before NotifyCollectionChangedAction.Add gets called
So as soon as I leave a cell in the row my itemchanged fires before the add and i get problems.
How can i idenitfy if row is being added instead of updated. I sue wish there was a UserUpdatedRow event
Any help is appreciated
Public Class ManageMemberType Public context As New MIMSModel.MIMSEntities Dim newMemType As MemType Dim updMemType As MemType Dim dmemtype As MemType Dim rtype As String Private Sub ManageCompanyType_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim query = (From m In context.MemTypes Select m).ToList RadGridView1.DataSource = query End Sub Private Sub RadGridView1_RowsChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCollectionChangedEventArgs) Handles RadGridView1.RowsChanged If e.Action = Telerik.WinControls.Data.NotifyCollectionChangedAction.ItemChanged Then Dim updrow As GridViewDataRowInfo = CType(e.NewItems(0), GridViewDataRowInfo) updMemType = MemType.CreateMemType(updrow.Cells("Type").Value.ToString) updMemType.Desc = updrow.Cells("Desc").Value.ToString DataAccess.UpdateEntity(updMemType, "MemTypes") End If End Sub Private Sub RadGridView1_UserAddedRow(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewRowEventArgs) Handles RadGridView1.UserAddedRow newMemType = MemType.CreateMemType(e.Row.Cells.Item("Type").Value.ToString) newMemType.Desc = e.Row.Cells.Item("Desc").Value.ToString Try context.MemTypes.AddObject(newMemType) context.SaveChanges() MsgBox("record Added") Catch ex As UpdateException e.Row.Delete() MsgBox(String.Format("The object could not be added. Make sure that a Member type of '{0}' does not aleady exist.", newMemType.Type)) End Try End Sub Private Sub RadGridView1_UserDeletingRow(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewRowCancelEventArgs) Handles RadGridView1.UserDeletingRow rtype = e.Rows(0).Cells(0).Value.ToString() Dim rcount = (From r In context.GetCompanyInfoes Where r.CompanyType = rtype Select r).Count If rcount > 0 Then MsgBox("There are " + rcount.ToString + " companies assigned to this member type, You cannot delete this type") Else Try dmemtype = MemType.CreateMemType(rtype) DataAccess.DeleteEntity(dmemtype, "MemTypes") Catch ex As Exception MsgBox("There was a problem deleting the Member type of " + rtype + " Please notify IT") End Try End If End Sub End Class