5
我在.Net應用程序中包含一個複選框列的DataGridView控件。我希望用戶能夠編輯複選框。我遇到的問題是,用戶檢查後無法檢測複選框的狀態。在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
由於提前,
邁克