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  
     
     
    <UserControl.Resources> 
     
               <DataTemplate Key = "MyTemplateOne"  > 
                 <telerikGridView:RadGridView.Columns> 
                     <telerikGridView:GridViewDataColumn   DataMemberBinding="{Binding ContractYearID}" /> 
                     <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding ContractYearDescription}"/>  
                     <telerikGridView:GridViewDataColumn  DataMemberBinding="{Binding YearStartDate}"/>   
                 <telerikGridView:RadGridView.Columns> 
     
                 </DataTemplate> 
                 <DataTemplate Key = "MyTemplateTwo"  >   
                   <telerikGridView:RadGridView.Columns> 
                      <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}"/>   
                      <telerikGridView:RadGridView.Columns> 
                 </DataTemplate> 
     
     
    </UserControl.Resources> 
     
     
         <telerikGridView:RadGridView>   
                    AutoGenerateColumns="False" 
                    ItemsSource="{Binding ContractYears, Mode=OneWay}" 
                    ItemTemplate="MyTemplateOne" OR "MyTemplateTwo"  
                    DataLoadMode="Asynchronous"/>  
             </telerikGridView:RadGridView>   
    <UserControl> 

     

     

     

     

     

  2. Pavel Pavlov
    Admin
    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