datagridview中的动态列计数

编程入门 行业动态 更新时间:2024-10-17 17:16:26
本文介绍了datagridview中的动态列计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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中的动态列计数

本文发布于:2023-10-28 05:05:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535607.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动态   datagridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!