Binding Templates to Objects When AutoGenerateColumns = true

2 posts, 0 answers
  1. StevenDale
    StevenDale avatar
    100 posts
    Member since:
    Apr 2007

    Posted 18 Mar 2013 Link to this post

    Telerik 2012.2.607.40

    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.

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


    Billy Jacobs

  2. Rossen Hristov
    Rossen Hristov avatar
    2478 posts

    Posted 19 Mar 2013 Link to this post



    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.

    Rossen Hristov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft R3 2016 release webinar banner
Back to Top