【发布时间】:2014-04-04 09:42:09
【问题描述】:
我有一个 datagridview 列,当表单加载时,它的值显示为 0.00,这是一个十进制值。当我单击特定单元格时,我想清除此列单元格值,当我离开单元格时,值(0.00)应该出现在单元格中。我附上一张快照以便更好地理解。
我希望在特定的单元格单击时使用它。十进制值可以吗?如何将单元格设置为空?我在单元格点击上做了一些代码,但没有结果。
private void dgvForecast_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
var cell = dgvForecast.Rows[e.RowIndex].Cells[e.ColumnIndex].Style as DataGridViewCellStyle;
decimal val = Convert.ToDecimal(dgvForecast.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
cell.Format = "";
dgvForecast.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = val.ToString("#");
cell.ApplyStyle(cell);
}
}
【问题讨论】:
标签: c#-4.0 datagridview