Atul Rokade

Atul Rokade

  • NA
  • 141
  • 42.2k

How to show grand total in datagridview footer

Jun 19 2016 11:34 AM
Hi all,

I want to show grand total in datagridview footer but here im not using any database connection i want to show grandtotal without using any database connection for this i wrote code but its not working
 
Note : im not using any database connection i want to show this total without any database connection
Two Coloumn total :
private void dataGridView1_CellEndEdit_1(object sender, DataGridViewCellEventArgs e)
{
double cell1 = 0;
double cell2 = 0;
if (e.ColumnIndex == 0 || e.ColumnIndex == 2)
{
if (!object.ReferenceEquals(dataGridView1.CurrentRow.Cells[0].Value, DBNull.Value))
{
cell1 = Convert.ToSingle(dataGridView1.CurrentRow.Cells[0].Value);
}
if (!object.ReferenceEquals(dataGridView1.CurrentRow.Cells[2].Value, DBNull.Value))
{
cell2 = Convert.ToSingle(dataGridView1.CurrentRow.Cells[2].Value);
}
if (cell1.ToString() != "" && cell2.ToString() != "")
{
dataGridView1.CurrentRow.Cells[6].Value = cell1 * cell2;
}
}
}

GrandTotal code :(this code is not working)

 
private void dataGridView1_DataSourceChanged_1(object sender, EventArgs e)
{
double Total = 0;
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
Total += Convert.ToDouble(dataGridView1.Rows[i].Cells["Rupees"].Value);
}
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Rupees"].Value = Total;
lblsum.Text = Convert.ToString(Total);
}
 
 
 

Answers (7)