我DataSet
不是空的。它有16行,
但我的网格没有行。我有bindingSource
,这里有一些代码:
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);
}
当我开始调试时,当涉及到i < grid.Rows.Count
时,它就会跳出for循环。知道为什么会这样吗?
答案 0 :(得分:4)
您需要直接将数据表分配给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);
}
它有效......