Data Transformation

2 posts, 0 answers
  1. StevenDale
    StevenDale avatar
    100 posts
    Member since:
    Apr 2007

    Posted 16 Nov 2009 Link to this post

    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)
         -> 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"
         -> 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.

  2. Pavel Pavlov
    Pavel Pavlov avatar
    2039 posts

    Posted 19 Nov 2009 Link to this post

    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top