i used code for below datagridview cells sum
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int sum = 0;
for (i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
if (dataGridView1.Rows[i].Cells[0].Value != null)
{
sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value.ToString());
label1.Text = Convert.ToString(sum);
}
}
}
}
but i want to below like my cell[0].value sum is shown in label is ok ,but if i can use multipled by any numbers like below image the answer should be = 40
see below details how its come
5+4 = 9 * 2 = 18
(18+2) * 2 = 40

Luv LPosted Nov 3, 2014, 1:27 AM
Vithal WadjePosted Oct 31, 2014, 2:29 PM
VulpesPosted Oct 31, 2014, 11:51 AM
}
However, I wouldn't like to be sure that this code will always work as I'm not 100% clear what the calculation basis is in all eventualities.
Luv LPosted Oct 31, 2014, 9:25 AM
anybody solve this problem yaar its too late.nibody have,t solution
Luv LPosted Oct 28, 2014, 6:02 AM
plz see below image for ref
correct answer should be 202 but it will come 448
see explaination how it will come
2*2 = 4
(3+4)*2 = 14
((10+4)*3+4)*4 = 184
now total is = 4 + 14 + 184 = 202
plz check?
Wim SturkenboomPosted Oct 21, 2014, 5:25 AM
Also, should the result of your example not be 60?
You can modify the below to suite your needs.
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int sum = 0;
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
try
{
int col0 = dataGridView1.Rows[i].Cells[0].Value == null ? 0 : Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value.ToString());
int multiplier =
dataGridView1.Rows[i].Cells[1].Value != null && !String.IsNullOrWhiteSpace(dataGridView1.Rows[i].Cells[1].Value.ToString()) ?
Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value.ToString()) :
dataGridView1.Rows[i].Cells[2].Value != null && !String.IsNullOrWhiteSpace(dataGridView1.Rows[i].Cells[2].Value.ToString()) ?
Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value.ToString()) : 1;
sum += col0;
sum *= multiplier;
label1.Text = Convert.ToString(sum);
}
catch (Exception ex)
{
label1.Text = ex.Message;
}
}
}
This code assumes that either the second or the third column contains a multiplier (but not both). I would normally not use the construction to calculate the multiplier but you might have a hard time explaining it to a teacher in case this is homework :-)