专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

DataGridView1_CellValueChanged 死循环了 小弟我的代码该如何修改

发布时间:2011-06-23 14:21:11 文章来源:www.iduyao.cn 采编人员:星星草
DataGridView1_CellValueChanged 死循环了 我的代码该怎么修改?
 Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
        ariginalColumn = DataGridView1.CurrentCell.RowIndex
        ariginalRow = DataGridView1.CurrentCell.ColumnIndex
        ifCellChanged = True
        '循环计算剩余数量()
        For i = 0 To DataGridView1.Rows.Count - 2
            Dim a As Double
            Dim b As Double
            a = DataGridView1.Rows(i).Cells(6).Value
            b = DataGridView1.Rows(i).Cells(7).Value
            If Not DataGridView1.Rows(i).Cells(6).Value Is DBNull.Value Or DataGridView1.Rows(i).Cells(7).Value Is DBNull.Value Then
                DataGridView1.Rows(i).Cells(8).Value = CStr(Val(a) - Val(b))
            End If
        Next
    End Sub

------解决方案--------------------
跟什么Flag没有关系。因为DataGridView1_CellValueChanged被级联触发,完全是可能事情,你不能想当然地弄一个Flag来回避正常的级联触发事件。

其实这是一个模式,就是赋值之前你先要检查一下,当两个值不同时才赋值。自然就不会出现死循环。
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: