验证 dlbDataGridView 中的 "dldm" 为能为空
private void dlbDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (dlbDataGridView.Columns[e.ColumnIndex].Name == "dldm")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dlbDataGridView.Rows[e.RowIndex].ErrorText = "大类代码不能为空";
e.Cancel = true;
}
}
}
注:1、dlbDataGridView.Columns[e.ColumnIndex].Name 默认为 dataGridViewTextBoxColumn1 若想采用字段名,须在编辑列中更改Name属性;
2、采用 [e.RowIndex].ErrorText 方式的错误信息提示时,只是在行的标识列中显示红色的“!”,当鼠标指向“!”时,才显示错误信息,可改用对话框的方式提示:
MessageBox.Show("大类代码不能为空!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);