datagridview的CellValidating问题
近日再用datagridview的时候出了个麻烦,代码如下:void uc2_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
string pat = @"^[\u4e00-\u9fa5]{2,4}$";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
if (e.ColumnIndex == 0 && e.RowIndex != -1)
{
Match m = r.Match(e.FormattedValue.ToString());
if (!m.Success)
{
e.Cancel = true;
MessageBox.Show("请输入中文姓名!", "警告");
}
}}
问题在于当cell输入的不是中文时CellValidating事件居然会调用三次,必须用鼠标点击三次messagebox才能关闭警告窗口,请问如果让他只调用一次呢?