当前位置:编程学习 > C#/ASP.NET >>

DataGridView数据验证提示错误时,窗口不能正常关闭

DataGridView中的某一单元格的数据不合法时(CellValidating事件中进行验证),
在DataGridView发生错误单元格所在行的前面显示错误提示。
这时,在一个button按下时,想关闭窗体,却不能关闭。
我处理的事件有
①DataError
        If e.Context = DataGridViewDataErrorContexts.Commit Then
            T_LEGAL_PROCEDURE_DataGridView.Rows(e.RowIndex).ErrorText = e.Exception.ToString
            e.Cancel = True
        End If
②DefaultValuesNeeded
③CellValidated
 Me.T_LEGAL_PROCEDURE_DataGridView.Rows(e.RowIndex).ErrorText = Nothing
④CellValidating 调用验证函数
 'If GridValidCodeCheck(T_LEGAL_PROCEDURE_DataGridView.Columns(e.ColumnIndex).Name, e.FormattedValue, e.ColumnIndex, e.RowIndex) = False Then
        '    e.Cancel = True
        '    Exit Sub
        'End If  
⑤RowValidated
 Me.T_LEGAL_PROCEDURE_DataGridView.Rows(e.RowIndex).ErrorText = Nothing
⑥RowEnter 
    大家有碰到过的吗?
请指教
--------------------编程问答-------------------- 看得头昏眼花,帮你顶个~~ --------------------编程问答-------------------- 按一下ESC然后不就可以关闭了吗?
或者改正不正确的数值,然后再关闭~ --------------------编程问答--------------------

现在要求直接关闭呢,同事的处理可以
俺的不知道为什么不行,调查一天了没结果 --------------------编程问答-------------------- 该回复被版主删除 --------------------编程问答-------------------- 我也遇到了,终于解决了。
首先,你可以在DataError事件函数里先写如果是按关闭按钮的话,就退出。
if (btnClose.Focused)
           return; --------------------编程问答-------------------- 只需要重写父类onclosing事件就可以了,在事件里面将datagridview的cellvalidating事件去掉e.cancel=false;就ok了,我用的c#的,代码如下:
this.dataGridView1.CellValidating -= dataGridView1_CellValidating; e.Cancel = false;
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,