What is the best way to retrieve control values form a DataTemplate inside a RowsDetailTemplate in a DataGrid?
05-11-2010 7:31 AM |
Hi everyone,
I need to save the whole information entered by the user in a datagrid, so I would like to know what is the best way to retrieve the control values form a DataTemplate inside a ItemsControl that is inside another DataTemplate in a RowsDetailTemplate in a DataGrid? I want to be able to do this when the user hits the "Save Button" outside the Grid (not a save button per datagrid row).
I already tried using a code like this:
myGrid.RowDetailsTemplate.LoadContent();
but this returns the template itself with no values in it.
I have found some threads that suggest of using the RowLoaded and LoadingRowDetails events to change the data in the controls inside a DataTemplate but I already use the LoadingRowDetails event to load the data inside the RowDetailsTemplate. Do I have to use these events to read the values from the RowDetailsTemplate/DataTemplate UI Controls anyway? If so, how do I do that? I tried different ways but the events don't get triggered when reading the datagrid items.
here is a snapshot of how my Datagrid looks like.
And Here is my XAML:
<RadGridView.RowDetailsTemplate>
<DataTemplate>
<StackPanel x:Name="rowDetailsStackPanel" Orientation="Horizontal">
<Grid x:Name="rowDetailsGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="103"/>
<ColumnDefinition Width="670"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel x:Name="rowDetailsGridStackPanel" Grid.Column="1" Grid.Row="0">
<ItemsControl x:Name="rowDetailsItemsControl">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid x:Name="rowDetailsGridItemsControl" Margin="0,1,0,1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="350"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<StackPanel x:Name="rowDetailsItemCheckBoxGridItemsControl" Grid.Column="0" Grid.Row="0">
<CheckBox x:Name="subItemCheckBox" IsChecked="{Binding subItemCheckBox, Mode=TwoWay}"></CheckBox>
</StackPanel>
<StackPanel x:Name="rowDetailsSubItemTextBlockGridItemsControl" Grid.Column="1" Grid.Row="0">
<TextBlock x:Name="subItemTextBlock" Text="{Binding subItemTextBlock, Mode=TwoWay}"/>
</StackPanel>
<StackPanel x:Name="rowDetailsSubItemTextBoxGridItemsControl" Grid.Column="2" Grid.Row="0" HorizontalAlignment="Left">
<TextBox x:Name="subItemTextBox" Text="{Binding subItemTextBox, Mode=TwoWay}" Width="300"/>
</StackPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Grid>
</StackPanel>
</DataTemplate>
</RowDetailsTemplate>
Thank you in advance