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 :
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);
}
7 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mageshwaran RPosted Nov 20, 2019, 6:08 PM
Puppy KumariPosted Nov 20, 2019, 4:34 AM
Vinay SinghPosted Jun 19, 2016, 1:23 PM
Atul RokadePosted Jun 19, 2016, 1:15 PM
Dharmesh SinghPosted Jun 19, 2016, 12:20 PM
Dharmesh SinghPosted Jun 19, 2016, 12:18 PM
Vinay SinghPosted Jun 19, 2016, 12:16 PM