3
Reply

sum of datagridview values

Shyja Abraham

Shyja Abraham

Feb 7 2011 4:01 PM
8.2k
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)