Hello,
I have combobox to which observable collection is bound. This collection is list of Person objects. Person class has 10 details including name. I display name in Combobox saying DisplayMemberPath=Name.
On selection change of combo, I need to show details of person selected in Datagrid below like age, gender etc.
Iin datagrid, I have datagridTextColumn set to corresponding property of Person class for every property as below.
<DataGridTextColumn Header="Name" Binding="{Binding ElementName=cboBox1, Path=SelectedItem.Name}"
I have above code for all columns bound to different property. But data is not displayed in datagrid on slection change of combo.
Below is my total code.
<Grid>
<ComboBox Height="25" Width="100" Name="cboBox1" DisplayMemberPath="Name" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=Persons}" SelectionChanged="cboBox1_SelectionChanged">
</ComboBox>
<DataGrid Name="dtgrdData" Grid.Row="1" ItemsSource="{Binding ElementName=cboBox1}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding ElementName=cboBox1, Path=SelectedItem.Name}" />
<DataGridTextColumn Header="Age" Binding="{Binding ElementName=cboBox1, Path=SelectedItem.Age}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
Any suggestions please.
Regards,
Harish.
Harish