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
2010-04-19 15:20:48