specifying ItemTemplate for RadGridView

2 posts, 0 answers
  1. Matt Meleski
    Matt Meleski avatar
    8 posts
    Member since:
    Oct 2009

    Posted 18 Nov 2009 Link to this post

    Hi ,

    My end goal is to do something similar to a ItemSource Control and dynamically switch out the the Column defintions
    for a Grid. In the below Xaml, there are two DataTemplates. I would like to be able to switch out the between MyTemplateOne and 
    MyTemplateTwo, by setting the   ItemTemplate property on the RadGridView. Of course this does not work. Is there some other way  way to do this?
    Something, that does work is a the RowDetailsTemplate property :
    RowDetailsTemplate="{StaticResource EmployeeInfoRowDetailsTemplate}"
    But I would like to do the same on the regular Rows.

    Thanks, Matt



    My end goal is to do something similar to a ItemSource Control and dynamically switch out the the Column defintions   
    for a Grid. In the below Xaml, there are two DataTemplates. I would like to be able to switch out the between MyTemplateOne and   
    MyTemplateTwo, by setting the   ItemTemplate property on the RadGridView. Of course this does not work. Is there some other way  way to do this?  
    Something, that does work is a the RowDetailsTemplate property :  
    RowDetailsTemplate="{StaticResource EmployeeInfoRowDetailsTemplate}" 
    But I would like to do the same on the regular Rows.  
    Thanks, Matt  
               <DataTemplate Key = "MyTemplateOne"  > 
                     <telerikGridView:GridViewDataColumn   DataMemberBinding="{Binding ContractYearID}" /> 
                     <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding ContractYearDescription}"/>  
                     <telerikGridView:GridViewDataColumn  DataMemberBinding="{Binding YearStartDate}"/>   
                 <DataTemplate Key = "MyTemplateTwo"  >   
                      <telerikGridView:GridViewDataColumn  DataMemberBinding="{Binding ContractYearID}" /> 
                         <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding ContractYearDescription}"/>  
                         <telerikGridView:GridViewDataColumn  DataMemberBinding="{Binding YearStartDate}"/>   
                         <telerikGridView:GridViewDataColumn  DataMemberBinding="{Binding YearEndDate}"/>   
                         <telerikGridView:GridViewDataColumn  DataMemberBinding="{Binding ContractAmount}"/>   
                    ItemsSource="{Binding ContractYears, Mode=OneWay}" 
                    ItemTemplate="MyTemplateOne" OR "MyTemplateTwo"  






  2. Pavel Pavlov
    Pavel Pavlov avatar
    2039 posts

    Posted 20 Nov 2009 Link to this post

    Hi Matt Meleski,

    Unfortunately this is difficult to do in xaml. The approach here would be - have a two collections of columns either declared in code behind or as static resources.
    Then when you need to switch the columns use the RadGridView.Columns.Clear() and then RadGridView.Columns.AddRange( .... ) passing here one of your collections.

    Looking at your sample code I note the set of columns is almost the same for the two cases and differs by only the last two columns. So you can also add/remove only those two columns in code behind or if they are always present - just toggle their visibility and hide them when not needed.

    Kind regards,
    Pavel Pavlov
    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.
Back to Top