I am working on a SilverLight app on ASPX with RIA services from Entity Framework backend. I have the loading of the DataGrid just fine including the related table data. I am now working on updating the fields with the combobox changes. As I debug I can see the changes on the entity object, but it does not persist. I tried calling CommitEdit on the DataGrid in the RowEditEnding event which just crashes the app with giving me the error.
Bind the CB's:
Private Sub dgStaff_PreparingCellForEdit(sender As Object, e As System.Windows.Controls.DataGridPreparingCellForEditEventArgs) Handles dgStaff.PreparingCellForEdit
columnIndex = e.Column.DisplayIndex
Dim cb As ComboBox = TryCast(e.EditingElement, ComboBox)
If cb IsNot Nothing Then
cb.DisplayMemberPath = "Description"
Select Case columnIndex
Case 2
cb.SelectedItem = curPerson.Station.StationId
cb.ItemsSource = stations
cb.SelectedValue = curPerson.Station.StationId
Case 3
cb.SelectedItem = curPerson.Shift.ShiftId
cb.ItemsSource = shifts
cb.SelectedValue = curPerson.Shift.ShiftId
Case 4
cb.SelectedItem = curPerson.Team.TeamId
cb.ItemsSource = teams
cb.SelectedValue = curPerson.Team.TeamId
End Select
End If
End Sub
Get the current entity object:
Private Sub dgStaff_BeginningEdit(sender As Object, e As System.Windows.Controls.DataGridBeginningEditEventArgs) Handles dgStaff.BeginningEdit
curPerson = CType(e.Row.DataContext, BMServiceRef.Personnel)
End Sub
Get the new values and apply them to the entity object:
Private Sub cb_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
Dim cb As ComboBox = DirectCast(sender, ComboBox)
Select Case columnIndex
Case 2
curPerson.StationId = CType(cb.SelectedItem, BMServiceRef.Station).StationId
Case 3
curPerson.ShiftId = CType(cb.SelectedItem, BMServiceRef.Shift).ShiftId
Case 4
curPerson.TeamId = CType(cb.SelectedItem, BMServiceRef.Team).TeamId
End Select
End Sub
Let me know if I can add any more info. Thanks for looking...