2

I have a DataGrid defined as such with a MVVM design pattern:

<DataGrid Margin="10" Height="385" Width="1000" ItemsSource="{Binding Inspection.Details}" SelectedItem="{Binding SelectedDetail, Mode=TwoWay}" AutoGenerateColumns="False" CanUserAddRows="False" x:Name="grdDetails" CanUserSortColumns="True" HorizontalScrollBarVisibility="Visible" CanUserResizeColumns="True">
     <DataGrid.Columns>
        <DataGridTemplateColumn   Header="Code" Width="120" SortMemberPath="MFGCode">
          <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
             <Grid>
                 <ComboBox FontSize="20" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}},Path=DataContext.MFGCodes}" DisplayMemberPath="Value" SelectedValuePath="Value"  SelectedValue="{Binding MFGCode,Mode=TwoWay}"></ComboBox>
             </Grid>
           </DataTemplate>
         </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>
   </DataGrid.Columns>
</DataGrid>

The Combobox is being populated correctly, by binding to a ObservableCollection within the ViewModel. There are also other columns (not presented here) that are being correctly bound to various properties on an Inspection defined in the view model.

On inital load, the combobox CORRECTLY binds to the selectedvalue on the InspectionDetail that represents the MFGCode.

The only problem is, when I change the value in the combobox, the new SelectedValue is not being saved to the SelectedDetail's MFGCode property as I would expect with a TwoWay binding.

I can provide ViewModel code as it would be helpful, just ask.

Thanks!

1 Answer 1

6

try this

SelectedValue="{Binding MFGCode,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.