我在.Net应用程序中有一个DataGridView控件,其中包含一个复选框列.我希望用户能够编辑复选框.我遇到的问题是我在用户检查后无法检测到复选框的状态.
如果最初选中该复选框,则一旦DataGridViewCheckBoxCell获得焦点,它将立即返回.但是,如果我再次单击该复选框并取消选中它,则它仍然会返回选中状态.从那时起,它将始终返回检查,无论复选框的实际状态如何,直到它失去焦点并再次获得它.
同样,如果复选框最初未选中,那么当它获得焦点时,无论复选框的实际状态如何,它都将在click事件中返回未选中状态.
这是我的代码.
Private Sub grdTemplates_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdTemplates.CellContentClick
Dim strValue As String = ""
Try
If Me.grdTemplates.Columns(e.ColumnIndex).Name = "colCurrentTemplate" Then
'The user clicked on the checkbox column
strValue = Me.grdTemplates.Item(e.ColumnIndex, e.RowIndex).Value
'THIS VALUE NEVER CHANGES WHILE THE DataGridViewCheckBoxCell HAS FOCUS
Me.lblTemplates.Text = strValue
End If
Catch ex As Exception
HandleError(ex.ToString)
End Try
End Sub
Run Code Online (Sandbox Code Playgroud)
提前致谢,
麦克风