Ajit N

Ajit N

  • NA
  • 352
  • 72k

how to get opening and closing balance using datagridview

Apr 14 2019 6:54 AM
Hello, i want to show the opening and closing balance in datagridview.
so, i tried below code on datagridview's sorted event.
  1. private void dataGridView1_Sorted(object sender, EventArgs e)  
  2.         {  
  3.             try  
  4.             {  
  5.                 for (int i = 1; i < dataGridView1.Rows.Count - 1; i++)  
  6.                 {  
  7.                     if (dataGridView1.Rows[i].Cells[4].Value.ToString() != "0")  
  8.                     {  
  9.                         dataGridView1.Rows[i].Cells[5].Value = Convert.ToInt32(dataGridView1.Rows[i-1].Cells[5].Value) - Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value);  
  10.   
  11.                     }  
  12.                     else  
  13.                     {  
  14.                         dataGridView1.Rows[i].Cells[5].Value = Convert.ToInt32(dataGridView1.Rows[i - 1].Cells[5].Value) + Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value);  
  15.   
  16.                     }  
  17.                 }  
  18.   
  19.             }  
  20.             catch (Exception ex)  
  21.             {  
  22.                  
  23.             }  
  24.   
  25.         }  
it show's me this type of output in datagridview which i displayed in below image
 
 
But as per my requirement i want this type of output in datagridview
 
 
 
so help how can i do this ? 

Answers (1)