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

Programmatically adding columns with display and edit templates for different data types

3 Answers 369 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anita
Top achievements
Rank 1
Anita asked on 27 Sep 2010, 04:49 PM
I display a collection of items in a RadGridView, each having a collection of parameters of possibly different types.

It works quite nicely if I use the resource definitions below along with an identical definition for each of the parameter columns:

01.<t:RadGridView.Resources>
02.    <DataTemplate DataType="{x:Type vm:AnalogParam}">
03.       edit template definition....
04.    </DataTemplate>
05.    <DataTemplate DataType="{x:Type vm:DigitalParam}">
06.       edit template definition....
07.    </DataTemplate>
08.    <DataTemplate DataType="{x:Type vm:DummyParam}">
09.       edit template definition....
10.    </DataTemplate>
11.      
12.    <DataTemplate DataType="{x:Type vm:AnalogParamDisplay}">
13.       display template definition....
14.    </DataTemplate>
15.    <DataTemplate DataType="{x:Type vm:DigitalParamDisplay}">
16.       display template definition....
17.    </DataTemplate>
18.    <DataTemplate DataType="{x:Type vm:DummyParamDisplay}">
19.       display template definition....
20.    </DataTemplate>
21.      
22.    <DataTemplate DataType="{x:Type bo:DigitalParamDesc}" >
23.       header template definition....
24.    </DataTemplate>
25.    <DataTemplate DataType="{x:Type no:AnalogParamDesc}">
26.       header template definition....
27.    </DataTemplate>
28.</t:RadGridView.Resources>
29.<t:RadGridView.Columns>
30.    .....
31.    <t:GridViewDataColumn Header="{Binding Descriptors[4]}" IsReadOnly="False" IsFilterable="False">
32.        <t:GridViewColumn.CellTemplate>
33.            <DataTemplate>
34.                <ContentPresenter Content="{Binding Params[4].DisplayWrapper}" />
35.            </DataTemplate>
36.        </t:GridViewColumn.CellTemplate>
37.        <t:GridViewColumn.CellEditTemplate>
38.            <DataTemplate>
39.                <ContentPresenter Content="{Binding Params[4]}" />
40.            </DataTemplate>
41.        </t:GridViewColumn.CellEditTemplate>
42.    </t:GridViewDataColumn>

Because the number of parameters in the grid is variable, I would like to add the columns programmatically instead of defining them in XAML.

How do I do that?

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 27 Sep 2010, 05:19 PM
Hi Anita,

You may take a look at our online documentation, demonstrating how to define columns programmatically. Furthermore, you can define the DataTemplates for CellEditTemplate and CellTemplate setting up those properties to the Resources added in the xaml file.

Regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Anita
Top achievements
Rank 1
answered on 27 Sep 2010, 06:13 PM

Thanks, but that doesn't really help me any further - I have already added simple columns successfully.

What I need to know is how to add columns programmatically that have the logic of the XAML example shown for parameter column no. 4.

In other words, column definitions

  • that use different bindings for the CellTemplate and the CellEditTemplate,
  • and that automatically revert to the type-specific templates defined in the grid resources (for column headers and cell content).
0
Maya
Telerik team
answered on 30 Sep 2010, 02:10 PM
Hi Anita,

Following up your requirements, I have prepared a sample project corresponding to them.
You may take a look at the application and let me know, if it satisfies your necessities.
 

Regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Anita
Top achievements
Rank 1
Answers by
Maya
Telerik team
Anita
Top achievements
Rank 1
Share this question
or