3
Answers

sum of datagridview values

Shyja Abraham

Shyja Abraham

10y
8.2k
1
I have form with datagridview with columns id,name,mark .and a textbox total.Iwant to find the  sum of the mark when we entered the values into the datagridview.


int sum=0;
 private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
                        

                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                sum += Convert.ToInt32(dataGridView1.Rows[i].Cells["mark"].Value.ToString());
                textBox1.Text = Convert.ToString(sum);
                
            }

        }




but the "Object reference not set to an instance of an object" error occurs, plz help;
Answers (3)