How to update a DataGrid column when another column is changed in the same row

I have a wpf DataGrid with a ComboBox column and another TextBox column. When I select a value in the ComboBox, I want the selected value to appear in the TextBox column on the same row. How can i do this. Thank.

+3


source to share


1 answer


Do all your manipulations in the ViewModel. Create a property for the combination Bind selectedItem, you can bind this property in the next column.



<DataGrid ItemsSource="{Binding ViewModel.Rows}" >
    <DataGrid.Columns>
        <DataGridTemplateColumn>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <ComboBox ItemsSource="{Binding ViewModel.ComboBoxItems}" SelectedItem="{Binding ViewModel.ComboBoxSelectedItem}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>

        <DataGridTextColumn Binding="{Binding ViewModel.ComboBoxSelectedItem.Name}" />

      

+3


source







All Articles