how to sum the integers in the i,j cells in data grid view

May 14 2009 4:44 PM
dear sir,
I have 2 problems that bothering me too much.
1. firstly, how to sum the integers in the cells from the cells of datagridview[0,0]. value to datagridview [jcols,irows].value.
2. secondly, how to multiply the integers in the cell of datagridview[0,0] to datagridview[jcols,irows].value

I paste my codes in here....
please someone help me...

public void acces1()
        {

            dataGridView2.Columns.Clear();

            for (int i = 0; i <= dataGridView1.Rows.Count - 1; i++)
            {
                string aa;
                aa = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value);
                dataGridView2.Columns.Add(aa, aa);
                dataGridView2.Rows.Add(aa);

            }
            foreach (DataGridViewRow k in this.dataGridView2.Rows)
            {

                k.HeaderCell.Value = dataGridView2.Rows[k.Index].Cells[0].Value;
                dataGridView2.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
            }

 public void calc1()
        {
            int a, b, c;
            int l = dataGridView2.Rows.Count - 1;
           
            for (int i = 0; i <= dataGridView2.RowCount - 1;i++ )
            {
                for (a = 0; a <= dataGridView2.ColumnCount - 2; a++)
                {
                    if (dataGridView2.Rows[i].Index != -1)
                    {
                        b = 0;
                        b= Convert.ToInt32(dataGridView2.Rows[i].Cells[0].Value.ToString());
                        c = Convert.ToInt32(dataGridView2.Rows[l].Cells[0].Value.ToString());
                        c = c + b;
                        dataGridView2.Rows[l].Cells[0].Value =c;
                    }
                    else
                    {
                        MessageBox.Show("huh!Please Tell me!");
                    }
                }

Answers (1)