How to bind the combo box inside the DataGrid.RowDetailsTemplate
Hi,
I have a data grid which has RowDetails.Template. In that i have another grid which will have the combo box that will bind data from a service. But that combo box is not binded and it is not populating. Please find the sample code below and help me out.
xaml:
===========
<data:DataGrid x:Name="dgSilverligh" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" AutoGenerateColumns="False" Foreground="Black" RowHeight="22" Margin="5,3,5,0"
ItemsSource="{Binding}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" MinHeight="250" >
<data:DataGrid.Columns>
<data:DataGridTemplateColumn Header="First Name">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton x:Name="hyberID" Content="{Binding FirstName, Mode=TwoWay}" Width="150" Height="25" Cursor="Hand" FontWeight="SemiBold" Foreground="RoyalBlue" VerticalAlignment="Center" ></HyperlinkButton>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
<data:DataGrid.RowDetailsTemplate >
<DataTemplate>
<StackPanel Background="LightBlue">
<StackPanel Orientation="Horizontal">
<TextBlock Text="This item has details." />
</StackPanel>
<StackPanel Orientation="Horizontal" >
<data:DataGrid x:Name="dgSilverligh_Inner" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" LoadingRow="dgSilverligh_Inner_LoadingRow" Width="100" >
<data:DataGrid.Columns>
<data:DataGridTemplateColumn Width="60">
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox x:Name="cmb1" Loaded="cmb1_Loaded" DisplayMemberPath="Name" VerticalAlignment="Center" HorizontalAlignment="Left" Width="60"></ComboBox>
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
</data:DataGrid>
</StackPanel>
</StackPanel>
</DataTemplate>
</data:DataGrid.RowDetailsTemplate>
xaml.cs
===========
private void cmb1Loaded(object sender, RoutedEventArgs e)
{
ComboBox ComboBox1 = new ComboBox();
ComboBox1.ItemsSource = objStage;
}
private void dgSilverligh_Inner_LoadingRow(object sender, DataGridRowEventArgs e)
{
DataGrid dg = (DataGrid)sender;
ComboBox cmb1 = dg.Columns[0].GetCellContent(e.Row) as ComboBox;
cmb1.ItemsSource = objStage;
cmb1.SelectedIndex = 0;
}
Thanks,
Vijay