Transpose a Collection

Posted by Joseph Melettukunnel on Stack Overflow See other posts from Stack Overflow or by Joseph Melettukunnel
Published on 2009-10-21T08:54:52Z Indexed on 2010/05/07 8:28 UTC
Read the original article Hit count: 358

Filed under:
|
|

Hello,

I've a list of different sizes of a T-Shirt, e.g. S, M, L. Since this might change for T-Shirts (sometimes we just have e.g. M, L), we load this into a List sizes.

Since most DataGrids (xamDataGrid, WPF Toolkit DataGrid) need Properties for binding to the Columns, I'd like to transpose somehow my data. Does anyone have an idea how to do this?

E.g. Instead of having List where Size { string sizeName, int available, int defect, int ordered}

    Avail.  Defect Ordered
[S]   1       2       3
[M]   1       2       3
[L]   1       2       3

I want an Object which has the Properties S, M, L containing the Values like this:

         [S]    [M]     [L]
Avail.    1      2       3
Defect    1      2       3
Ordered   1      2       3

The problem here is that I don't know how many sizes will be available for the tshirt, it might be 3, 4, or 10.

Thanks for any help

Cheers

PS: Here is a mockup of how the final grid should look like http://img39.imageshack.us/img39/9161/multirowspangridfixedel.png

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf