Bind gridview to Child Collection

4 posts, 0 answers
  1. Darren
    Darren avatar
    5 posts
    Member since:
    Mar 2016

    Posted 31 Mar Link to this post

    Here is a simplified version of what i'm trying to achieve.

    I have a product class with a collection of user defined fields

    public class Product
    {
        public string ProductName { get; set; }
        public string Category { get; set; }
        public List<UserDefinedField> userDefinedfields;
    }
    public class UserDefinedField
    {
        public string Name { get; set; }
        public string Value { get; set; }
    }

    I can bind the name and category easily in Xaml.

    <telerik:GridViewDataColumn DataMemberBinding="{Binding ProductName}"  />
    <telerik:GridViewDataColumn DataMemberBinding="{Binding Category}" />

    I'd like to also bind the collection of user defined field to the end of the grid in code behind.  I've tried this but no luck, the columns are created but no data is loaded.

    foreach (UserDefinedField udf in products[0].UserDefinedFields)
    {
        ProductGrid.Columns.Add(
             new GridViewDataColumn
             {
                 Header = udf.Name,
                 DataMemberBinding = new Binding(udf.Value)
             });
     }

     

    Thank you in advance.

     

     

     

     

     

  2. Stefan X1
    Admin
    Stefan X1 avatar
    521 posts

    Posted 31 Mar Link to this post

    Hi Darren,

    The built-in mechanisms that the control provides for such scenarios are the Hierarchy and RowDetails. Can you please check out the referred help articles and let me know whether they correspond to your requirement, or I am missing something?

    Best Regards,
    Stefan X1
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Darren
    Darren avatar
    5 posts
    Member since:
    Mar 2016

    Posted 31 Mar Link to this post

    Hi Thanks for the reply,

    The details row looks promising but what I was really after was being able to add the User Defined Fields as additional columns at the end of the grid.  I'd like the user to be able to filter and group by fields they have added.

  5. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 05 Apr Link to this post

    Hi,

    Can you consider using a Combobox in the CellTemplate or our ComboboxColumn?

    Regards,
    Yoan
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top