Hi all I am binding a DataTable
to the DataGridView
with some of the columns along with some amount fields.
I need to show the sum of the columns for each of the amount filed in DataGridView
. I have already searched for many options to add a footer to the DataGridView
. Is there any possibility to sum up few columns in the DataTable
so that I can display the data in DataGridView
?
This is my datatable data roughly:
Name Address Amount DiscountAmount
XYZ ABC 100.00 20.00
ABC DEF 150.00 0.00
Required result is:
Name Address Amount DiscountAmount
XYZ ABC 100.00 20.00
ABC DEF 150.00 0.00
250.00 20.00
I have already tried some thing like following - and it didn't worked:
DataRow lRow = lDTGrid.NewRow();
lRow[0] = "Totals";
for (int i = 1; i < lDTGrid.Columns.Count; i++)
{
lRow[lDTGrid.Columns[i].ColumnName] = lDTGrid.Compute("Sum(" + lDTGrid.Columns[i].ColumnName + ")", "");
}