我试图在表单加载中更改网格复选框值,问题是当我运行并跟踪代码时,它工作正常,但网格上没有任何变化。
代码块:
For Each row As DataGridViewRow In DataGridView3.Rows
Dim c As Integer
c = row.Cells(4).Value
If c = 2 Then
row.Cells(selctWin.Name).Value = True
Else
row.Cells(selctWin.Name).Value = False
End If
Next
答案 0 :(得分:1)
请尝试以下代码:
Private Sub DataGridView3_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)
DataGridView3.CommitEdit(DataGridViewDataErrorContexts.Commit)
End Sub
在单元格内容点击(checkboxCell
此处)而不结束编辑模式时,它将允许更改提交。请参阅documentation有关CommitEdit
方法的更多信息。