1
我有DataSet
這不是null。它有16行,爲什麼grid.Rows.Count始終爲0?
但我的網格沒有行。我有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循環。任何想法爲什麼會發生?
,而不是'grid.Rows.Count'嘗試'ds.Tables [0] .Rows.Count' –
也許需要'grid.DataBind()'? –
[DataGridView.Rows.Count爲0]可能的重複(http://stackoverflow.com/questions/23130156/datagridview-rows-count-is-0) – Claudius