如何检查datagridview是null还是空 [英] How to check if datagridview is null or empty
问题描述
我有一个按钮来执行操作。但如果我的datgridview为空或null,它会发出一条消息,说明它是空的或空的。
我尝试了什么:
if(mydatagridview.rows.count == 0)
{
//消息
}
但这是检查我拥有的每一行如果我有大量的行。还有其他方法可以获得更快的逻辑/代码吗?感谢
I have a button that does an operation. but if my datgridview is empty or null it will prom a message saying it is null or empty.
What I have tried:
if (mydatagridview.rows.count == 0)
{
//message
}
but this is checking every row that I have what if I have tons of rows.is there other way for faster logic/code than this? thankss
推荐答案
检查null和空:
To check for null and empty:
if (mydatagridview == null || mydatagridview.Rows.Count == 0)
{
// message
}
Rows.Count不不计算调用时的行,但返回添加和删除行时更新的值。调用它来检查DataGridView是否为空是没有问题的。
Rows.Count doesn't calculate the rows at the time of calling, but returns a value that is updated when adding and deleting rows. There is no problem calling it to check if the DataGridView is empty.
这篇关于如何检查datagridview是null还是空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!