我的代码有问题。我使用vb和mysql作为数据库。我也有datagridview,其中frist列是一个checkedboxcolumn。我想要的是:当用户选中复选框时,一些数据将自动显示在标签中。
我的代码在这里。实际上它正在运行。但问题是当我检查第二个复选框时,我首先检查的数据会显示。
Dim counter As Integer = 0
For Each oRow As DataGridViewRow In DataGridView1.Rows
Dim isSelected As Boolean = Convert.ToBoolean(oRow.Cells("checkBoxColumn").Value)
If Me.DataGridView1.Focused = True Then
If isSelected = True Then
counter += 1
If counter = 1 Then
oRow.DefaultCellStyle.BackColor = Color.Red
Label17.Text = oRow.Cells("Book_ID").Value.ToString()
Label25.Text = oRow.Cells("Call_Number").Value.ToString()
Label21.Text = oRow.Cells("Title").Value.ToString()
If oRow.Cells("checkBoxColumn").Value = False Then
Label17.Text = ""
Label25.Text = ""
Label21.Text = ""
End If
ElseIf counter = 2 Then
oRow.DefaultCellStyle.BackColor = Color.Red
Label20.Text = oRow.Cells("Book_ID").Value.ToString()
Label26.Text = oRow.Cells("Call_Number").Value.ToString()
Label19.Text = oRow.Cells("Title").Value.ToString()
oRow.Cells("checkBoxColumn").Value = False
MsgBox("You can Borrow 2 Books at a Time")
End If
End If
End If
Next