views:

136

answers:

1
+1  A: 

In my opinion you need a pivot grid control.

There are good ones at Infragistics and DevExpress

Edit: but, if you do it manually, I would have something like this (from the top of my head)

Class Data
   Public Categories() as List
   Public Types() as List
   Public table as list( of row )
End Class

Class Row
   Public Category as string
   Public Type as string
   Public Group as string
   Public Header1 as string
   Public Header2 as string
   Public cell as string
End Class

Then I would code a function like: (pseudo-code)

function AddData( Category, Type, Group, theData )
    1. Search if the Category exist in array of categories, else add it
    2. Search if the Type exist in array of Types, else add it 
    3. add the rec
end function 

function DisplayData( )
   //show headers
   For each category in data.categories
      For each Type in data.categories
         AddColumn( Category, Type )
      next
   next
   //get the groups
   for each group in (from g in data.table select g.group).distinct
      for each category in data.categories
         for each type in data.types
            cell = (from r in data.table where r.category = category and r.type = type and r.group = group)
            if cell is nothing then
               addcell("null")
            else
               addcell(cell)
            end if
         next
      next
   next

I think I left behind the several rows that may have the common category, but you will get the idea.
It's not the best in performance, but it is easy to follow.

Eduardo Molteni
Thanks for the tip. These controls look like an easy way to implement this. I would prefer to avoid third party controls. If you were going to implement this where would you start?
VoidDweller
Sorry about the delay Eduardo. I have been thinking something along these lines. I hope to have a chance to flesh out building the Grid this week. I'll post it when it's working. Thanks.
VoidDweller