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

specifying ItemTemplate for RadGridView

1 Answer 216 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Matt Meleski
Top achievements
Rank 1
Matt Meleski asked on 18 Nov 2009, 10:27 PM

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> 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 20 Nov 2009, 01:52 PM
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.
Tags
General Discussions
Asked by
Matt Meleski
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or