Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I bind a DataGridComboBoxColumn to EntityFramework using MVVM?
    primarykey
    data
    text
    <p>I'm trying to get a DataGridComboBoxColumn working with my ViewModel. Everything appears to work correctly but when I change the value of the combo box, the entity isn't changed. </p> <p>The datacontext of the window has these properties:</p> <p><strong>ItemsSource</strong></p> <pre><code>Public Property AllEnergySources() As ObservableCollection(Of EnergySourceViewModel) </code></pre> <p><strong>SelectedItemBinding</strong></p> <pre><code> Private _CurrentEnergySource As EnergySourceViewModel Public Property CurrentEnergySource() As EnergySourceViewModel Get Return _CurrentEnergySource End Get Set(ByVal value As EnergySourceViewModel) _CurrentEnergySource = value OnPropertyChanged("CurrentEnergySource") End Set End Property </code></pre> <p>I feel the problem lies with how I populate CurrentEnergySource in the ViewModel that is the DataContext:</p> <pre><code>Sub New(SelectedEntity as EquipmentEnergySource) AllEnergySources = New ObservableCollection(Of EnergySourceViewModel) //Select all EnergySources from the EntityFramework Dim EnergyEntities = From esr in db.EnergySources Select esr //Loop through to convert Entity POCO to Collection of ViewModels For Each es In EnergyEntities _AllEnergySources.Add(New EnergySourceViewModel(es)) //Optionally Set the newly created ViewModel to SelectedItemBinding object If es.EnergySourceID = SelectedEntity.EnergySourceID Then _CurrentEnergySource = _AllEnergySources.Last End If Next End Sub </code></pre> <p>When I create the backing collection for the combobox, if the model is the selected one, I set that viewmodel to be the CurrentEnergySource but after that point it is disconnected(and that's the problem)</p> <p>What should I reference in CurrentEnergySource so that it updates the model when the combo box changes?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload