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

Binding Templates to Objects When AutoGenerateColumns = true

1 Answer 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
StevenDale
Top achievements
Rank 2
StevenDale asked on 18 Mar 2013, 07:36 PM
Telerik 2012.2.607.40

Scenario:
1. I have an object let's say VitalSign.
     Vital Sign (Object)
        - Name 
        - Value

2. A user may enter 1 to n Vital signs as a single set of entries. This action will create one row. For that row there will be n number of columns based on the number of vital signs the user entered during that discrete operation. If the user performs the action a second time then there will be 2 rows and the number of columns will be Max(Number Of Vital Signs For Discrete Operation). 
Ex Display:
Temp        Heart Rate        Blood Pressure        Pulse
98                  55                        120/80                120   - Discrete Entry 1 (4 Vital Signs)
                      65                        125/90                124   - Discrete Entry 2 ( 3 Vital Signs)
                      62                                                            - Discrete Entry 3 ( 1 Vital Sign)

3. So I dynamically generate a table to create the appropriate columns which contains all columns for any row which has a value. In the example above there is no Blood Sugar value for any discrete entry so this column would not be generated.
4. When I create my columns I create them as objects like this.
vitalSignsTable.Columns.Add(vitalSign, typeof (VitalSign));

4. Next I Bind a RadDataGrid to the dynamically generated DataTable and set the AutoGenerateColumns = true
5. Next I handle the AutoGeneratingColumn event and set the column Template to the template below.

My question is, how do I bind the Text property in the TextBox in my template to a value from the VitalSign object?. If I DO NOT use a template, and instead just create a ToString() for my VitalSign object, I can display the correct values in the Grid, but I need to use the VitalSign's object properties for other reasons.

NOTE: I know I can Bind to ItemArray[Index].Property to bind directly to the object, but to do this, I have to know the correct index before runtime, and since the columns are dynamically determined at runtime, I have no way to know this.

TEMPLATE
<DataTemplate x:Key="PatientVitalSignTemplate" >
<TextBox Text="{Binding ???????????}"  />
</DataTemplate>

Thanks,

Billy Jacobs

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 19 Mar 2013, 10:08 AM
Hi,

Hello,

I am afraid that we are unable to think of any possible way to achieve what you are after with this architecture and with the static DataTemplates. Furthermore, this architectural issue does not seem to be particularly related to RadGridView as a control, i.e. the same architectural problem should be present if you use any other ItemsControl such as the stock DataGrid. Please, correct us if we are wrong and if you can handle this exact scenario with the stock WPF DataGrid for example. We will check if our grid is lacking in functionality compared to the standard WPF DataGrid.

Regards,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
StevenDale
Top achievements
Rank 2
Answers by
Rossen Hristov
Telerik team
Share this question
or