This question is little bit similar to the question in WPF - change the selected Item of one combobox to the selected item of another combobox, but there is a difference. I have already made a comment in it and asked how to do this new change. But no one replied, that's why I thought of posting it as a new question. Please do not mark this as a duplicate of the previous one, because it is not.
I have the following in my viewmodel.
private <MyClass> _firstComboBoxSelection;
public <MyClass> FirstComboboxSelection
{
set { _firstComboBoxSelection=value; OnPropertyChanged("SecondComboboxSelection"); }
get { return _firstComboBoxSelection ; }
}
private <MyClass> _secondComboBoxSelection;
public <MyClass> SecondComboboxSelection
{
set { _secondComboBoxSelection=value; }
get { return _secondComboBoxSelection ; }
}
At the same time , I have a datagrid in my .xaml file.
<DataGrid ItemSource="{Binding SomeData}">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="cmbFirst"
ItemSource="{Bnding SomeData_2}" SelectedItem="{Binding FirstComboboxSelection}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="cmbSecond"
ItemSource="{Bnding SomeData_3}" SelectedItem="{Binding SecondComboboxSelection}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
What I want is to change the third column's combo box's selected item when second column's selected item is changed. This is a grid. So, this change should occur only in one row. That is if I change the selected item of second column's third row's combo box, then the value of third column's third row's combo box's selected item should be changed. Others should remain as it is.
But , according to what I have done in my view model, changing the selected item of second column's one specific row changes the third column's all rows' selected items. Can someone help me to fix this ?
protected void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
SecondComboboxSelection = SomeSampleData;
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
Aucun commentaire:
Enregistrer un commentaire