如何以编程方式将空数据网格视图单元格值设置为零(0)。 [英] How to set programmatically empty data grid view cell values taken zero(0).
本文介绍了如何以编程方式将空数据网格视图单元格值设置为零(0)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am creating windows application using c# 2010, here I am using data grid view, in my data grid view having 3 columns and many more rows. I am not entered all columns, alternatively I am enter the cells value.
Ex :
Slno mts cm
1 2
2 3
3 3
Here I want how set programmatically empty data grid view cell values taken zero(0).
什么我试过了:
如何以编程方式设置空数据网格视图单元格值为零(0)。
What I have tried:
How to set programmatically empty data grid view cell values taken zero(0).
推荐答案
绑定数据后调用下面的函数使空单元格为0
After binding the data call the below function to make the empty cells as 0
private void MakeZeroForEmptyCells()
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
string value = Convert.ToString(cell.Value);
cell.Value = string.IsNullOrWhiteSpace(value) ? 0 : cell.Value;
}
}
}
你应该打电话给这个函数 CellValueChanged
在单元格填充空值时更新数据。
and you shall call this function on CellValueChanged
to update the data when the cell is filled with empty value.
这篇关于如何以编程方式将空数据网格视图单元格值设置为零(0)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文