This is a migrated thread and some comments may be shown as answers.

What is the best way to retrieve control values form a DataTemplate inside a RowsDetailTemplate in a DataGrid?

3 Answers 48 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ville
Top achievements
Rank 1
Ville asked on 11 May 2010, 04:55 PM

What is the best way to retrieve control values form a DataTemplate inside a RowsDetailTemplate in a DataGrid?

 

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.

RowDetailsIssue

 

 

 

 


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

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 12 May 2010, 05:50 PM
Hi Giuliano,

Please, share more details about your scenario - do you want to save the newly-added data in the database or you want to save it in an object ? 
 

Kind regards,
Maya
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ville
Top achievements
Rank 1
answered on 12 May 2010, 06:07 PM
Firt of all thanks for your response,

I want to save the data to the database.

Thank you

0
Maya
Telerik team
answered on 13 May 2010, 12:36 PM
Hello Giuliano,

Good  approach for saving changes in a database is to use WCF RIA Services. Their DomainDataSource has a method called SaveChanges() which does exactly what you need. Furthermore, you can use the property of the DomainDataSource - SubmitChangesCommand that can be used in the definition of the button directly in xaml. 
I am sending you a sample project so that you can see and test the proposed solution. 

Sincerely yours,
Maya
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Ville
Top achievements
Rank 1
Answers by
Maya
Telerik team
Ville
Top achievements
Rank 1
Share this question
or