Totalling DataGrid rows

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a DataGrid bound to a DataTable and I'd like to have one row of totals.

I was hoping that I can have a row on the bottom of the DataGrid's results
which will always be visible (no matter how you scroll and no matter how you
filter the table) which adds up values in particular columns. Is it possible
to do this?

If not, what's the smartest way to handle this?

Should I create a second table which can somehow use the sum( ) functions to
total up the rows of another table? Then this table I guess would have to be
shown in a separate DataGrid under the one displaying the results
 
MrNobody,

The DataGrid as it exists doesn't handle this. There might be some
third party grids that handle this though.

Hope this helps.
 
MrNobody,

I should have been more specific. It's not possible if you want it in
one grid with the DataGrid.

The best way that you could do it would to do as you suggested, and have
a second data grid, where you have it bound to a second table which has the
sum of the values in the first table. You could create a relation (where
the sum table is related to all the fields in the other table), and then sum
up on the parent fields (you could create a column with an Expression
property set to this).
 
Thanks again Nicholas,

Now if I wanted to use the Expression property on the second table to sum
the values in the first table, does that require that a DataRelation is
created between the two?
 
MrNobody,

You have one of two choices. The first would be to actually append the
column to the original data table (or a copy of it) and have the expression
just be the sum of the field.

The other is to create a relation between the table and another table
which has one row. Basically, you have to add a column where the values are
all one value, and then set the column in the relation in the parent table
(the sum table here) to have the same value. Then you can set the
expression property to be the sum of the field in the child table (which
would be all the rows).
 
Back
Top