datagridview cell 验证事件

private void baseDataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (e.ColumnIndex == 5 && this.baseDataGridView1.CurrentCell.IsInEditMode)
{
string sVal = this.baseDataGridView1.CurrentCell.EditedFormattedValue.ToString();
try
{
decimal.Parse(sVal);
}
catch (Exception)
{
e.Cancel
= true;
MessageBox.Show(
"请输入数字!");
}

}
}
原文地址:https://www.cnblogs.com/wucg/p/1765708.html