首页 文章

选中/取消选中时,Windows窗体DataGridView复选框值始终为True

提问于
浏览
0

我们有一个Windows窗体应用程序,它有一个DataGridView控件,其中包含一个带有复选框的列 .

enter image description here

当用户检查或取消选中DataGridView中行/单元格中的框时,我们希望获得更新的值(true或false) .

问题是,当使用我们当前的代码实现时,值总是被评估为true .

private void gvDocumentContents_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex == 6)
        {
            DataGridViewRow dgvr = gvDocumentContents.Rows[e.RowIndex];
            DataGridViewCheckBoxCell cbCell = dgvr.Cells[6] as DataGridViewCheckBoxCell;
            MessageBox.Show(cbCell.Value.ToString());
        }
    }

我已经看到了关于这个主题的类似问题,但是在花了一天的大部分时间后,我在尝试的其他一些解决方案上没有取得多大成功 .

谢谢

1 回答

相关问题