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

Bind gridview to Child Collection

3 Answers 59 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 31 Mar 2016, 09:30 AM

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.

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 31 Mar 2016, 01:16 PM
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.
0
Darren
Top achievements
Rank 1
answered on 31 Mar 2016, 02:06 PM

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.

0
Yoan
Telerik team
answered on 05 Apr 2016, 08:15 AM
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.
Tags
GridView
Asked by
Darren
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Darren
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or