处理DataGridView中的空单元格 [英] Handle empty cells in DataGridView
问题描述
我想写的时候DataGridView中的某些细胞是null或空的条件。
为例,如果细胞[1]不为空或空,方法必须运行和...
我写它以某种方式,但其中一些没有工作,和一个他们的工作,但其现在我problem.As你没有很好的解决方案,空和空在DataGridView的不同。
此外,我的DataGridView未被绑定到数据库。
我怎么能做到这一点的最佳方法?
的问候。
I want to write a condition for when some cells of DataGridView are null or empty. For example if cells[1] isn't null or empty , a method must be run and ... I wrote it in some way , but some of them didn't work, and one of them work but its not good solution for my problem.As you now ,empty and null are different in DataGridView. Additionally , My DataGridView has not been bound to database. How can i do that in best way? Regards.
推荐答案
DataGridViewCell的对象有值方法,它返回callvalue为对象,就可以转换为字符串值,然后核对这个字符串null或空。
DataGridViewCell object has "Value" method which returns callvalue as object, That value you can convert to string then check this string against null or empty.
string val = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value as string;
if(string.isNullorEmpty(val) ==false)
{
// your method run.
}
这篇关于处理DataGridView中的空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!