Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Silverlight
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...
Posted 18-Apr-13 17:11pm
Edited 20-Apr-13 9:35am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I have a workaround. In the combobox selectionChanged event I save selection to server. In the cellEditEnd event I update the dataGrid again. I would still like to get the current value to show in the combobox - the selectedIndex. If someone can help with that part(or the rest) I'll give you the solution.
The twoWay binding does not work and this is why I have to rebind the dataGrid.
 
<DataTemplate>
  <ComboBox ItemsSource="{Binding Path=stations,Mode=TwoWay}" SelectionChanged="cb_SelectionChanged" DropDownClosed="dd_closed" />
</DataTemplate>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You need to bind the SelectedValue

DisplayMemberPath="name"
SelectedValuePath="id"
SelectedValue="{Binding Path=buildingId, Mode=TwoWay}"
ItemsSource="{Binding Buildings}"
Width="160">
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 26 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100