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

Data Transformation

1 Answer 51 Views
GridView
This is a migrated thread and some comments may be shown as answers.
StevenDale
Top achievements
Rank 2
StevenDale asked on 16 Nov 2009, 05:52 PM
I have the following scenario: (NOTE: this is just a simplified example of my data schema)

I have a list of Orders. Each Order has a list of OrderDetails. Each OrderDetail has a type. I want to display a grid that shows for each order each OrderDetail.Type as a column.

So you have what would look like this: (Keep in mind that there are other detailtypes that are not used e.g. Type 2, 4, 5 and that new detailtypes can be created)
Order1
     -> Detail1.Type = "Type 1"   Detail1.Value = "Value for Detail 1 Type 1"
     -> Detail2.Type = "Type 3"   Detail2.Value = "Value for Detail 2 Type 3"
     -> Detail3.Type = "Type 6"   Detail3.Value = "Value for Detail 3 Type 6"
Order2
     -> Detail1.Type = "Type 1"   Detail1.Value = "Value for Detail 1 Type 1"
     -> Detail2.Type = "Type 6"   Detail2.Value = "Value for Detail 2 Type 6"
Order 3
     -> Detail1.Type = "Type 3"   Detail1.Value = "Value for Detail 1 Type 3"


I want to show a column for each detail type used in any orderdetail for any order. Also, there is no fixed list of these types because new orderdetail types can be added. So basically I am showing my orderDetail values horizontally instead of vertically and I create a column for each detailtype that exists in any orderdetail of an order even though some orders will not necessarily have a orderdetail with one of the types.
NOTE: A type can only be in one orderdetail per order.

And my resulting Grid should look like this:

Order  |                 Type 1                 |                 Type 3                 |                 Type 6                 |
   1           Value for Detail 1 Type 1         Value for Detail 2 Type 3           Value for Detail 3 Type 6
   2           Value for Detail 1 Type 1                                                        Value for Detail 2 Type 6
   3                                                        Value for Detail 1 Type 3


I have gone so far as creating a Dictionary of <Order, OrderDetail> and placed null in the OrderDetail value if it does not have a value for a type but I cannot figure out how to display this in a grid without programatically creating the grid.

Any ideas would be appreciated.

Thanks,

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 19 Nov 2009, 02:26 PM
Hi Billy ,

Since no predefined count of columns or column mappings exist I would recommend the following approach :

Dynamically create and  populate a DataTable from your data and leave RadGridView to autogenerate its columns.
RadGridView for WPF  has a good support for working with DataTables and this will keep the solution simple while giving the 'dynamic' option of building columns.

Kind regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
StevenDale
Top achievements
Rank 2
Answers by
Pavel Pavlov
Telerik team
Share this question
or