Click here to Skip to main content
15,895,746 members

Silverlight DataGrid CellEditTemplate combobox databinding issue.

Idle_Force asked:

Open original thread
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:
VB
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:
VB
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:
VB
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...
Tags: Silverlight

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900