我在datagridview中进行动态计数,我已按照以下方式完成此操作。但是我无法解决它,也许其他人会知道如何正确执行我的执行。 我希望它能够做到这一点; 列必须计算(如行)e.x.有30个列需要从0到30进行计数并检查每列1by1,现在数据表被放置在加载过程中,因此我们不能再从数据表中获取值,只需填充数据网格视图。 如果以某种方式我可以解决细胞[f](计数从0到30的细胞)而不是它将被解决但是显然我不能。 很难解释,但我希望你会理解它。
Iam making a dynamic count in datagridview, i've done this in the followed ways. yet i can't solve it, perhaps someone else will know how to do my execution right. i want it to do the followed; the columns have to be counted (as rows) e.x. there are 30 columns you need to count from 0 to 30 and check each column 1by1, now the datatable is disposed on the load procedure so we can't get values from the datatable anymore, just the datagridview which is populated. if somehow i could solve the cells[f] (count the cells from 0 to 30) than it would be solved but apperently somehow i cannot. its hard to explain but i'd hope you will understand it.
int columnz = datatable.columns.count; columns.Text = columnz.ToString();
for (int i = 0; i < dataGridView1.RowCount - 1; i++) { for (int f = 0; i <= Convert.ToInt64(columns.Text); i++) { if (dataGridView1.Rows[i].Cells[f].Value.ToString() == null) { dataGridView1.Rows.RemoveAt(i); i--; } } }
我也试过做过细胞(f.tostring) ())...我不知道该怎么做。
i've also tried to do Cells(f.tostring())... i dont know what to do anymore.
推荐答案尝试下面的代码 try below code for (int row = 0; row < dataGridView1.Rows.Count; ++row) { bool isEmpty = false; for (int col = 0; col < dataGridView1.Columns.Count; ++col) { object value = dataGridView1.Rows[row].Cells[col].Value; if (value == null || value == DBNull.Value || String.IsNullOrWhitespace(value .ToString()) { isEmpty = true; break; } } if (isEmpty) { dataGridView1.Rows.RemoveAt(row--); } }
更多推荐
datagridview中的动态列计数
发布评论