gpt4 book ai didi

vb.net - 问题检测 DataGridView 中的复选框状态

转载 作者:行者123 更新时间:2023-12-04 20:22:28 26 4
gpt4 key购买 nike

我在包含复选框列的 .Net 应用程序中有一个 DataGridView 控件。我希望用户能够编辑复选框。我遇到的问题是在用户检查复选框后我无法检测到它的状态。

如果复选框最初被选中,那么一旦 DataGridViewCheckBoxCell 获得焦点,它就会返回选中状态。但是,如果我再次单击复选框并取消选中它,它仍然会返回选中状态。从那时起,无论复选框的实际状态如何,它都将始终返回选中状态,直到它失去焦点并再次获得焦点。

同样,如果复选框最初未选中,那么当它获得焦点时,无论复选框的实际状态如何,它都会在单击事件中返回未选中状态。

这是我的代码。

    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

提前致谢,

麦克风

最佳答案

将其包含在您的代码中:

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

来源: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcelldirtystatechanged.aspx

关于vb.net - 问题检测 DataGridView 中的复选框状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4888543/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com