我想为DataGridView的某些单元格为空或空时编写一个条件。 例如,如果单元[1]不为空或空,则必须运行一个方法,并且... 我以某种方式编写它,但其中一些不起作用,其中一个工作,但其中一个不起作用解决方案为我的问题。就像你现在,DataGridView中的空和空是不同的。 此外,我的DataGridView尚未绑定到数据库。 我怎样才能以最好的方式做到这一点? 此致敬礼。在DataGridView中处理空单元格
2
A
回答
5
DataGridViewCell对象具有“Value”方法,该方法将callvalue作为对象返回,可以将该值转换为字符串,然后将该字符串检查为null或空。
string val = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value as string;
if(string.isNullorEmpty(val) ==false)
{
// your method run.
}
0
单元格值是一个对象。空单元格值为空。
DataTable/DataView在Empty时使用DbNull.Value。
字符串以长度= 0是的String.Empty
您需要验证三个选项。
0
如果你的列和行布局是固定的,那么你可以调用你的函数在细胞验证数据网格
void dataGridView2_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
e.Cancel = false;
if (e.RowIndex == 1 && e.ColumnIndex == 0)
{
if(string.IsNullorEmpty(e.FormattedValue.ToString())
// method call
}
}
0
//just replace from Value to FormattedValue like that
string val = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].FormattedValue as string;
if(string.isNullorEmpty(val))
{
// cell is empty
}
else
{
// cell is not empty
}
事件
相关问题
- 1. 在DataGridView中处理空单元格
- 2. 处理单元格中的空值
- 3. 处理网页中的空单元格
- 4. 在DataGridView custon列中处理单元格分析
- 5. DataGridView System.InvalidOperationException单元格不在DataGridView中
- 6. wxPython GridSizer - 处理空单元格
- 7. 如何处理空单元格
- 8. DataGridView单元格
- 9. Datagridview更改非空单元格的单元格颜色
- 10. VB.NET - 如果不Datagridview单元格为空
- 11. 计数非空单元格的DataGridView
- 12. datagridview单元格的空值vb.net
- 13. 在Datagridview中格式化单元格
- 14. 熊猫 - 处理空单元
- 15. 如何处理空的datagridview?
- 16. 在C#中读取DatagridView中的空单元格#
- 17. 检查datagridview的单元格中的空值或空值
- 18. 如何在C#中清空DataGridView的单元格?
- 19. 编辑时在DataGridView单元格中强制非空值
- 20. 在datagridview中停止空白单元格 - VB.NET
- 21. 如何禁用DataGridView中点击空单元格在C#
- 22. 在vb.net DataGridView中只读单元格
- 23. 防止在DataGridView中选择单元格
- 24. 在DataGridView中更改单元格的值
- 25. 在DataGridView单元格中插入路径
- 26. 在datagridview中合并单元格
- 27. 如何在DataGridView中编辑单元格?
- 28. 在datagridview中为单元格着色
- 29. VBA:跳过处理空白单元格(其中包含公式)
- 30. 如何处理excel文件中的空白单元格java