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

How to autogenerate colums for New With {c, o.OrderId}

5 Answers 49 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Peter Meinl
Top achievements
Rank 1
Peter Meinl asked on 21 Feb 2010, 01:05 PM

When binding the GridView to a LINQ result specifying entity names ("c" in the example below) without attributes the GridView displays their type name only and does not autogenerate colummns for their attributes:

Dim q = From c In qc Join s In qs On c.CustomerID Equals s.CustomerID  
 Select New With {c, s.Size}  
DataGrid1.ItemsSource = q.ToList  
 
does not autocreate the grid columns for "c", it displays the type name.  
 

The grid displays:
WpsApp1.NorthwindService.Customers | small
WpsApp1.NorthwindService.Customers | big

How can I make the GridView autogenerate columns for entities in "Select New {}"?

5 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 24 Feb 2010, 03:39 PM
Hello Peter Meinl,

RadGridView can only generate columns for the immediate properties of the data items that are displayed. I guess that in your scenario you are getting two columns - one for the c in "{c, s.Size} "  and one for the Size property. At the moment columns for sub-properties can only be created manually. 


Sincerely yours,
Milan
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
Peter Meinl
Top achievements
Rank 1
answered on 24 Feb 2010, 04:01 PM
In "Select New With {c, s.Size}"
"c" returns all properties of Customers.
Analogous to a "select c.* "  in SQL.
0
Milan
Telerik team
answered on 01 Mar 2010, 11:57 AM
Hello Peter Meinl,

c will indeed hold all properties of Customers but the anonymous class that is created will look something like this:

public class AnonymousClass1
{
    public c Customer
    {
        get;
        set;
    }
  
    public int Size
    {
        get;
        set;
    }
}

It will have only two properties and RadGridView will generate columns for those two properties. All Customers properties will be encapsulated within the c property. If you would like to expose other properties you could try something like:

Select New With {c, s.Size, c.Property1, c.Property2}


Sincerely yours,
Milan
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
Peter Meinl
Top achievements
Rank 1
answered on 01 Mar 2010, 01:04 PM
I am looking for a generic solution, where I do not have to specify each property.
Analogous to the output from this SQL

select

 

c.*, o.OrderID from Customers c inner join Orders o on c.CustomerID = o.CustomerID

 

0
Accepted
Milan
Telerik team
answered on 04 Mar 2010, 05:12 PM
Hello Peter Meinl,

Well, that cannot be achieved automatically and there are quite a few possible solutions. One solution is to use the so called MicroModels which allows you to define dynamic properties on classes. It also allow you to automatically "replicate" properties from one object to another (AllProperties mthod). For example, you can create a simple class called BaseEntity with two properties Customer and Order and try something like this:

Dim q = From c In qc Join s In qs On c.CustomerID Equals s.CustomerID  
 Select As New BaseEntity(c, s)

Using MicroModel you can create a BaseEntityView which has all properties of c and some of s with just a few lines of code. And them use this BaseEntityView to bind the grid.

Best wishes,
Milan
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
Peter Meinl
Top achievements
Rank 1
Answers by
Milan
Telerik team
Peter Meinl
Top achievements
Rank 1
Share this question
or