问题描述
private void dgvGroupDet_CellValidating(对象发送者,DataGridViewCellValidatingEventArgs e)
{
如果(dgvGroupDet.Columns [e.ColumnIndex] .Name ==& quot; Name& quot;)
{
如果(String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dgvGroupDet.Rows [e.RowIndex] .ErrorText =
& quot;名称不能为空& quot ;;
e.Cancel = true;
}
}
}
私有void dgvGroupDet_CellEndEdit(对象发送者,DataGridViewCellEventArgs e)
{
dgvGroupDet.Rows [e.RowIndex] .ErrorText = String.Empty;
}
注意:我正在尝试在datagridview中执行此代码以进行验证,它将可以正常工作,但是由于验证,我无法关闭我的Form.
private void dgvGroupDet_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (dgvGroupDet.Columns[e.ColumnIndex].Name == "Name")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dgvGroupDet.Rows[e.RowIndex].ErrorText =
"Name must not be empty";
e.Cancel = true;
}
}
}
private void dgvGroupDet_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dgvGroupDet.Rows[e.RowIndex].ErrorText = String.Empty;
}
Note: I m trying to do this code for validation in datagridview it will work complete but due to validation i can''t close my Form.
推荐答案
这篇关于datagridview_CellValidating事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!