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

RowDetails problem

5 Answers 150 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 30 Jan 2012, 09:57 PM
Hi,

in my application I have a RadGridView for who I create his columns dynamically on a specific event in my application. For each row in this grid, I need a sub grid. To achieve this, I create a GridViewToggleRowDetailsColumn dynamically.
 
In my XAML, I defined a <telerik:RadGridView.RowDetailsTemplate><DataTemplate><telerik:RadGridView x:Name="subSetGrid".

If I want to create dynamically the columns of my "subSetGrid" and assign it's "DataSource" to simething, how I can do to achieve this???

Thank's 

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 31 Jan 2012, 09:51 AM
Hello,

The RowDetails are a part of the corresponding row, so you can easily get all the elements using ChildrenOfType<T> () extension method. For example if your main GridView is 'clubsGrid':

var selectedRow = this.clubsGrid.ItemContainerGenerator.ContainerFromItem(this.clubsGrid.SelectedItem);
if(selectedRow != null)
{
     var child = selectedRow.ChildrenOfType<RadGridView>().FirstOrDefault();
}

In the case above 'child' will be the first RadGridView defined inside the template.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Oliver
Top achievements
Rank 1
answered on 31 Jan 2012, 02:56 PM
Hi,

if I create columns dynamically at my app startup just before assigning ItemSource to my grid, can you tell me if the proposed solution should work too?

Thank's
0
Dimitrina
Telerik team
answered on 31 Jan 2012, 03:50 PM
Hi,

 Actually the last suggestion that I gave you is not a good one. It is much more better to use the events of the parent or the details GridView.
For example you could use the RowDetailsVisibilityChanged event of the parent RadGridView. Then when the row is expanded you could add the desired columns and set the ItemsSource of the e.DetailsElement (that is the subSetGrid in your case). Or you could subscribe for the Loaded event of the Details RadGridView (subSetGrid) and then add the desired columns and set the ItemsSource there.

I am not sure what do you mean by "create columns dynamically at my app startup just before assigning ItemSource to my grid". Do you mean that you would like to initially create the columns and then set the ItemsSource?
 

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Oliver
Top achievements
Rank 1
answered on 31 Jan 2012, 04:02 PM
Hi,

what I mean by "create columns dynamically at my app startup just before assigning ItemSource to my grid" is when my app start, I call my backend to get all grids definitions, col type, alignment, etc... When I get all the definitions, I create dynamically the columns in each grids. After that, I set the datasource of each grid regarding the data I need to have base of my columns definition.

In my DataTemplate for my rowdetail. I have more than one control, I have a page control with 4 pages, in each page I have a grid.

So the problem is If I want to create dynamically the columns of each subgrids at my app startup I don't know how todo it. Regarding of the columns I created,  I have to create alson a dynamic ItemSource regarding the data my cutomer need to have in their grids.

Thank's
0
Rossen Hristov
Telerik team
answered on 31 Jan 2012, 05:19 PM
Hello,

Here is what you should do. 

1. Attach to the LoadingRowDetais event of the master grid. This event is fired only once for a given row -- the very first time that the end user expands its row details.

2. In the event handler of the event, you have e.DetailsElement. This is the top-level FrameworkElement that you have placed in your RowDetailsTemplate. If this is the child grid you can cast it directly to RadGridView. If this top-level element is something else, let's say a StackPanel or another container that contains the child grid, you should find the reference to your child grid by calling the ChildrenOfType<RadGridView> method on e.DetailsElement.

3. Once you have a reference to the child grid, you can do anything in the world to it, including adding columns based on your criteria and setting its ItemsSource. You have a reference to the grid so you are free to do anything with it.

Of course -- these procedure will the same each time the user open's a row details for the first time. You can't get hold of a child grid before that because it has not been created yet. RowDetails are loaded on demand, which means that if the end user never expands the row details for a certain row, then they will never be loaded. This is for performance reasons.

I hope this makes sense.

Please, read the row details documentation carefully. All of the above is already described there. This topic is the one that exactly describes what you are looking for.

Thank you for you understanding.

Regards,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Oliver
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Oliver
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or