2011-05-15 169 views
1

我有一些用vb.net编写的DataGridView代码。 (datasource附件中没有内容。如何检测checkBox是否已选中或未选中?读取单元格的值

此代码奇怪地在随机时间报告TRUE或FALSE。它甚至变成ONcheckbox比该行其他行我点击。

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick 
    Dim whichGrid As DataGridView = CType(sender, DataGridView) 

    Dim rowClicked As Int16 = e.RowIndex 

    Call MsgBox(rowClicked & vbCrLf & whichGrid.Rows(rowClicked).Cells(4).Value) 

End Sub 

所有我在这里看到(和其他国家)的其他例子似乎并没有帮助。他们的解决方案始终是:

  • 只需检查单元格的VALUE。
  • 只要学习c#,并学会将其转换为vb.net。
  • 只需检查VALUE为空,或为空或“”或全部。
  • 将VALUE转换为bool。
  • 改为将它附加到数据源。
  • 设置TrueValue和FalseValue。

我已经尝试了无数其他方法,似乎没有一个在vb.net中实际获得checkbox ON/OFF值。

回答

0

演员单元格的值,以布尔:

Dim RowIndex As Integer = ... 
Dim ColumnIndex As Integer = ... 

Dim IsTicked As Boolean = CBool(DataGridView1.Rows(RowIndex).Cells(ColumnIndex).Value) 

If IsTicked Then 
    MessageBox.Show("You ticked the box.") 
Else 
    MessageBox.Show("You cleared the box.") 
End If