编程论坛's Archiver

homesite 发表于 2007-11-20 11:33

DataGridView的问题!

<P>关于DataGridView行验证的"虫"(问题最为严重,也最复杂),看以下代码:<BR>   '验证一行的“银行编号”是否为空<BR>    Private Sub DataGridView1_RowValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.RowValidating<BR>        If blnLoadForm Then Exit Sub '加载窗体中跳过行验证<BR>              If e.RowIndex = Me.DataGridView1.Rows.Count - 1 Then Exit Sub<BR>              If String.IsNullOrEmpty(Me.DataGridView1.Rows(e.RowIndex).Cells("银行编号").Value.ToString.Trim) Then<BR>                     Me.DataGridView1.Rows(e.RowIndex).Cells("银行编号").Selected = True<BR>                     Me.DataGridView1.BeginEdit(True)<BR>                     Me.DataGridView1.Rows(e.RowIndex).ErrorText = "银行编号不能为空"<BR>                     blnRowValidated = False<BR>                     e.Cancel = True<BR>                     Exit Sub<BR>              End If<BR>                blnRowValidated = True<BR>        Me.DataGridView1.Rows(e.RowIndex).ErrorText = Nothing<BR>    End Sub</P>
<P>问题描述如下:这段程序所在的窗体如果是以单独窗体运行的话是没有问题的,但如果是以MDI的子窗体运行的话,如果DataGridView行验证信息不能满足时单击其它控件(如Button控件)整个程序将没有响应而且CPU占用率达到90%以上,但如果单击其它单元格则没有问题。经发现如果去除e.Cancel=True语句则没有问题,但是这样的话如果单击其它单元格时行验证不能满足时又无法中止后续操作。<BR><BR><BR>附件为测试项目,大家可以下载后试一下就知道了,还请大家看看有什么好的解决之道。谢谢!<BR><BR><BR></P>
[attach]30567[/attach]<BR><BR><BR>

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.