我目前在VB.net,Windows窗体应用程序中工作。我有一个datagridview,我想使用一个按钮来更新复选框中检查的某些行。但是,我很难选择复选框单元格。这是一个数据绑定源,它与sql客户端一起运行。
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim row As DataGridViewRow
Dim cell As DataGridViewCell
Dim i As Integer = 0
With DataGridLine2
For Each row In .Rows
For Each DataGridViewCheckBoxCell In .Rows
If DataGridViewCheckBoxCell.checkstate = 1 Then
Using conn1 As New SqlConnection(connstring)
conn1.Open()
Using comm1 As SqlCommand = New SqlCommand("UPDATE Production.dbo.tblFCordered SET Ordered = true", conn1)
End Using
End Using
ElseIf DataGridViewCheckBoxCell.checkstate = 0 Then
Exit Sub
End If
Next
Next
End With
End Sub