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);
}
Vinay SinghRank #604 · 4K reputationPosted Jun 19, 2016, 8:16 AM EDT
Dharmesh SinghRank #1,207 · 1.5K reputationPosted Jun 19, 2016, 8:18 AM EDT
Dharmesh SinghRank #1,207 · 1.5K reputationPosted Jun 19, 2016, 8:20 AM EDT
Atul Rokade146 reputationPosted Jun 19, 2016, 9:15 AM EDT
Vinay SinghRank #604 · 4K reputationPosted Jun 19, 2016, 9:23 AM EDT
Puppy KumariRank #3,859 · 384 reputationPosted Nov 19, 2019, 11:34 PM EST
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 20, 2019, 1:08 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts