private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
double c = 0.0;
dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty;
if(dataGridView1.Columns[e.ColumnIndex].DataPropertyName == "")
{
if(!double.TryParse(e.FormattedValue.ToString(),out c) || c<0.0)
{
dataGridView1.Rows[e.RowIndex].ErrorText = "数量输入有误!";
e.Cancel = true;
}
}
}
要编辑结束后才能执行事件
{
double c = 0.0;
dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty;
if(dataGridView1.Columns[e.ColumnIndex].DataPropertyName == "")
{
if(!double.TryParse(e.FormattedValue.ToString(),out c) || c<0.0)
{
dataGridView1.Rows[e.RowIndex].ErrorText = "数量输入有误!";
e.Cancel = true;
}
}
}
要编辑结束后才能执行事件
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货