I'm populating a Telerik RadGrid with data from a DataTable (
System.Data.DataTable). As I'm supporting someone else's application, I can't use any other data source or display control.
In my grid I have three columns: let's say they are Widgets Produced (column A), Faulty Widgets (column B) and Faultiness Proportion (column C). The database query provides these for me and does the calculation C = B / A.
I have a totals row (a Telerik
GridFooterItem) at the bottom of the grid. In columns A and B Telerik calculates the totals for those columns for me. We can't calculate the correct value for the 'total' of column C from column C alone: we have to populate it with (the sum of B) / (the sum of A).
I've managed to do this by handling the
DataBound event of the RadGrid and manually populating the cells in the footer. (I had to catch the
GridFooterItem in the
ItemCreated event, then put values in it in the
DataBound event, after it had automatically calculated the totals for A and B for me.) This feels pretty hacky - maybe there's a better way...?
Anyway, the important bit is this:
My grid is split into groups so I also need to populate column C in the
GridGroupFooterItems. I can't get my hacky technique to work in this case: I'm finding the footer cell I want with
myGridFooterItem["WidgetsProduced"], but I can't get the group footer cells with
myGridGroupFooterItem["WidgetsProduced"] - it just isn't a dictionary.
I've tried using
myGridGroupFooterItem.Cells, but this
TableCellCollection contains a couple more cells than I'd expect, so accessing them by integer index feels a tad ropey (especially as this is a user-defined report, so the columns may be in any order).
So: how do I populate these cells with my calculation?