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

DataTemplate for GridView columns collection?

3 Answers 51 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 30 Jan 2012, 06:15 PM
Is it possible to use a DataTemplate for a GridView columns collection?
I want to define my columns once and use it in multiple views

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 31 Jan 2012, 07:34 AM
Hello Erik,

Generally, you can define a DataTemplate in the Resources section and set it for each column you want afterwards. However, if you need to display different properties in your grid that might not be a good approach. What is the exact scenario that you want to achieve ? Do you want to have same columns with same values or you want to apply different style - like setting a background for example ?  

All the best,
Maya
the Telerik team

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

0
Erik
Top achievements
Rank 1
answered on 31 Jan 2012, 05:21 PM
Hi Maya,

I want to have the same columns with the same values and the same style, and use them in different RadGridViews in different Views
0
Maya
Telerik team
answered on 31 Jan 2012, 05:42 PM
Hello Erik,

In this case you can follow the idea mentioned above - to define DataTemplate in the Resources section, set its Key attribute and use is as CellTemplate for all the column you want.
For example:

XAML:
<DataTemplate x:Key="myDataTemplate>
   <TextBlock />
</DataTemplate>
 
C#:
this.clubsGrid.Columns[1].CellTemplate = (DataTemplate)this.Resources["myDataTemplate"];
 

Greetings,
Maya
the Telerik team

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

Tags
GridView
Asked by
Erik
Top achievements
Rank 1
Answers by
Maya
Telerik team
Erik
Top achievements
Rank 1
Share this question
or