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
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.
"c" returns all properties of Customers.
Analogous to a "select c.* " in SQL.
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.
Analogous to the output from this SQL
select
c.*, o.OrderID from Customers c inner join Orders o on c.CustomerID = o.CustomerID
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.