Datagridview_cellvalue仅在第二次尝试时更新

时间:2015-11-29 16:06:01

标签: vb.net winforms

DirtyStateChanged让我在单击复选框时立即提交

Private Sub dataGridView4_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DataGridView4.CurrentCellDirtyStateChanged
    If DataGridView4.IsCurrentCellDirty Then
        DataGridView4.CommitEdit(DataGridViewDataErrorContexts.Commit)
    End If
End Sub

Private Sub DataGridView4_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView4.CellValueChanged

    For c As Integer = 2 To DataGridView4.ColumnCount - 1

        If DataGridView4.Rows(e.RowIndex).Cells(c).Value = True Then

            'Disable this persons' row on datagridview5
            Dim aName As String = DataGridView4.Rows(e.RowIndex).Cells(0).Value
            For Each dRow As DataGridViewRow In DataGridView6.Rows
                If dRow.Cells(0).FormattedValue = aName Then
                    dRow.ReadOnly = True

                    For Each cell As DataGridViewCell In dRow.Cells
                        dRow.Cells(cell.ColumnIndex).Style.BackColor = Color.LightGray
                    Next
                    'DataGridView6.Update()
                End If
            Next
        End If
    Next
End Sub

当我点击datagridview3上的一个复选框时,它应该使用新的backcolor和readOnly更新datagridview5上的行。

似乎发生的事情似乎是第一次点击复选框时似乎无效。它在第二次尝试时确实很有效。

如何在第一次尝试时验证?

0 个答案:

没有答案