【问题标题】:How to see if a datagridviewcheckbox is checked or not如何查看是否选中了datagridview复选框
【发布时间】:2014-06-03 01:48:01
【问题描述】:

我创建了一个带有 DataGridViewCheckBoxColumn 的 datagridview。最初,我读入我的数据并将复选框的值设置为如果数据存在则设置为 true,否则设置为 false。这很好用,但是如果我将复选框的状态从以前的状态更改为选中或未选中,我将无法阅读此更改。当我尝试保存它总是显示的数据时,复选框的原始状态。

复选框被点击后如何重新读取它的值?

我在这里尝试了解决方案: How to check a checkbox created with VB's DataGridViewCheckBoxColumn on Runtime

使用:DirectCast(DataGridView1(0, 2).Value, Boolean)

但这对我不起作用。当我查看它时,我总是得到复选框的原始状态。如果该框最初被选中而我取消选中它,该值仍将显示 True。

【问题讨论】:

  • 为什么怯懦地投反对票而没有评论?这是一个合法的问题。

标签: vb.net checkbox datagridview


【解决方案1】:

您可能正在查看错误的行(您正在查看索引为 0 的第一行)。您可以使用 DataGridView_CellEndEdit 事件来查找复选框的值,就像这样...

If e.ColumnIndex = 2 Then 'this is the columnIndex of your checkbox column
    If MyBindingSource.Current("CheckBoxColumnName") = true then
        'the column is checked, so do something
    End If
End If

【讨论】:

    猜你喜欢
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    相关资源
    最近更新 更多