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

Set a user control to a data template using C#

4 Answers 107 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 06 Jan 2010, 07:05 AM
Good day, I have copied your examples that use the RowDetailsTemplate. Attached is an image showing that I load another user control into the RowDetailsTemplate. This is set in the XAML below with X:key = "SiteClassificationUc" etc, as per your examples. So when I click the GridViewToggleRowDetails button, I can see the User Control. So far so good. My questions are;

1 I would like to set the user control into the RowDetailsTemplate using C#, so depending on the ActivityType (as shown in the image), I would like to add a different user control. A possible solution to this is using your example..
 this.radGridView.RowDetailsTemplate = (DataTemplate)this.LayoutRoot.Resources["EmployeeInfoRowDetailsTemplate"];
However, I would need to know how I could get access to the instance of the EmployeeInfoRowDetailsTemplate at runtime. so I prefer to create the instance of the user control at runtime.

2 I would like to fire an event when I click the GridViewToggleRowDetails button, so that I can get the Activity Type and populate the different user controls in the RowDetailsTemplate with data.

Any examples or help much appreciated.

<Grid x:Name="LayoutRoot">

 

 

<Grid.Resources

 

 

 

<DataTemplate x:Key="SiteClassificationUc">  

 

 

<local:SiteClassificationUc />
</DataTemplate>
</Grid.Resources>
<tg:RadGridView x:Name="gxThingActivity" AutoGenerateColumns="False" Margin="0" CanUserFreezeColumns="False"

 

 RowDetailsVisibilityMode="VisibleWhenSelected" RowDetailsTemplate="{StaticResource SiteClassificationUc}"

 

 

ScrollMode="RealTime"

 

 

 

HorizontalAlignment="Left"

 

 

 

RowIndicatorVisibility="Collapsed">

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 06 Jan 2010, 11:44 AM
Hello Steven,

1. Place an empty StackPanel or Grid in the RowDetailsTemplate. Attach to the LoadingRowDetails event of the grid. In the event handler of this event, e.DetailsElement will be a reference to the row-particular instance of the StackPanel/Grid you have defined in the row details template. Sine e.DataContext will be the data item of the row for which row details are loading, you can read its ActivityType and based upon it decide what child control to add to the empty container and how to fill them up with data.

If you think that data might change between two consecutive showings of a row's details, you might consider attaching to the RowDetailsVisibilityChanged event instead of the LoadingRowDetails event.

2. This will be solved if you implement the scheme I have described above.

To learn more about RowDetails, please consult the online documentation. You can also check out some more advanced row details topics on my personal blog.

Let me know if you have any other questions.

Regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Karthikeyan
Top achievements
Rank 1
answered on 16 Sep 2011, 10:10 AM
Hi Ross,

I'm also facing the same issue with loading RadChart with the Row. I explained in the following link with telerik.
http://www.telerik.com/community/forums/silverlight/gridview/gridviewtogglerowdetailscolumn-content-datatemplate-as-radchart.aspx#1803448

Can you please explaining me the code what you have defined as text in last reply.
So that I can fix my issue. As well I let me know your blog link of the above issues.
Please I would greatly appreciate/thankful for your reply/answer.

Thanks,
Karthikeyan Manickam.
0
Rossen Hristov
Telerik team
answered on 19 Sep 2011, 08:32 AM
Hi Karthikeyan,

Could you please send us a small sample project that demonstrates the issue you are faced with. Thanks in advance.

All the best,
Ross
the Telerik team

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

0
Karthikeyan
Top achievements
Rank 1
answered on 19 Sep 2011, 11:00 AM
Hi Ross,

I got the help from MAYA-TELERIK team.
In my previous post, I mentioned a link. Please have a look.
My issue got fixed, and I gave the code also.

Thanks for your support.

Cheers...
Karthikeyan Manickam.
Tags
GridView
Asked by
Steven
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Karthikeyan
Top achievements
Rank 1
Share this question
or