1

I have DataSet which is not null. It have 16 rows,

enter image description here

but my grid have no rows. I have bindingSource, here is some code:

bindingSource.DataSource = ds.Tables[0]; //ds is DataSet
grid.DataSource = bindingSource;

double sum1 = 0;
for (int i = 0; i < grid.Rows.Count; ++i)
{
    sum1 += Convert.ToDouble(grid.Rows[i].Cells[13].Value);
}

When I start debugging, when it comes to i < grid.Rows.Count it just jump out of for loop. Any idea why is that happening?

Logerfo
  • 469
  • 5
  • 17
nemostyle
  • 794
  • 4
  • 11
  • 32

1 Answers1

4

you need to directly assign the data table to DataGridView DataSource..

grid.DataSource = ds.Tables[0];

double sum1 = 0;
for (int i = 0; i < grid.Rows.Count; ++i)
{
    sum1 += Convert.ToDouble(grid.Rows[i].Cells[13].Value);
}

It Works....

Logerfo
  • 469
  • 5
  • 17