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!");
}
}
Loading

Vimal KandasamyRank #2,151 · 661 reputationPosted May 15, 2009, 3:15 AM EDT
in your code,where you got error actually?...
I have some doubts on your code...
} In the above function,you just add rows and columns based on dgv1's 2nd column values. But adding its value as column is ok.But in adding row, you specify value for one cell. But in 2nd iteration of above for loop,no of columns become 2.so when you add single cell row it may not correct. and in calc1().you want add all rows's Cells[0] and show in last row of dgv2. am i correct?. but what is the use of highlighted for loop below. public void calc1() { int a, b, c; int l = dataGridView2.Rows.Count - 1; for (int i = 0; i for (a = 0; 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!"); } } you can add values like int sum=0; for (int i = 0; i <= dataGridView2.RowCount - 1;i++ ) { sum=sum+int.Parse(dataGridView2.Rows[i].Cells[0].Value.ToString()); } and at the end.you can directly assign like below. dataGridView2.Rows[dataGridView2.RowCount - 1].Cells[0].Value = sum;