Vb.net Datagridview\u cellvaluechanged仅在第二次尝试时更新
DirtyStateChanged允许我在单击复选框时立即提交Vb.net Datagridview\u cellvaluechanged仅在第二次尝试时更新,vb.net,winforms,Vb.net,Winforms,DirtyStateChanged允许我在单击复选框时立即提交 Private Sub dataGridView4_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DataGridView4.CurrentCellDirtyStateChanged If DataGridView4.IsCurrentCellDirty Then DataGridView4
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上的复选框时,它应该使用新的背景色和只读更新datagridview5上的行
第一次单击复选框时,它似乎不起作用。不过,在第二次尝试时,它确实非常有效
如何使其在第一次尝试时生效?@varocabas该复选框只需单击一次即可生效,但要使
CellValueChanged
只需单击一次,您应处理CellContentClick
并调用CommittedIt
。单击后会立即提升CellValueChanged
。但正如您所说,代码似乎按预期工作,我删除了我的答案,因为我不知道CurrentCellDirtyStateChanged
也会起作用。@RezaAghaei我看到了您删除的答案,但没有阅读它。OP的方法有点奇怪(对于复选框列,CellContentClick
或CellClick
或类似的方法肯定是正确的),我误解了它。但只有一件事:使用您的方法(CellContentClick
),您不需要使用ComitEdit
。OP的建议是:只需依靠一个更合适的事件(如您建议的CellContentClick
),忘记CurrentCellDirtyStateChanged
,CommittedIt
以及所有这些。感谢您的回答。似乎即使将所有内容都放在CellContentClick
中,也需要我做两次尝试才能更新另一个datagridview。如果你们想看视频,我可以快速截屏。