【问题标题】:How to get datagridviewcheckboxcolumn value c#?如何获取datagridviewcheckboxcolumn值c#?
【发布时间】:2017-08-19 03:07:25
【问题描述】:

在我的窗口表单应用程序中,我有一个 datagridview,它有一个复选框列,我想检索它的值是否被选中

    if ((bool)dataGridView1[columnindex,rowindex].Value ==true )
{
   MessageBox.show ("checked");
 }

但它不起作用 请回答我

【问题讨论】:

标签: c#


【解决方案1】:

这应该可以正常工作:

var value = dataGridView1[columnindex, rowindex].Value

因此,如果您说“它不起作用” - 不仅仅是您需要向我们提供有关您遇到的错误等的更多信息。

【讨论】:

  • 它也不起作用它说'对象引用未设置为对象的实例'
  • 没什么好说的,我只想在 cellcontentclick 事件检查复选框时检索复选框值
  • 你知道怎么调试吗?你怎么得到columnindexrowindex
  • e 。行索引和 e 。列索引
  • 我能找到的任何方式
【解决方案2】:

你可以试试下面的代码sn-p

foreach (DataGridViewRow roow in dataGridView1.Rows)
{
   DataGridViewCheckBoxCell chkchecking = roow.Cells[0] as DataGridViewCheckBoxCell;

    if (Convert.ToBoolean(chkchecking.Value) == true)
    {
    }
}

【讨论】:

    【解决方案3】:
    DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dataGridView1.CurrentCell;
    bool ischecked = (bool)checkbox.EditedFormattedValue;
    if (ischecked == true)
    {
    MessageBox.Show("True")
    }
    

    这段代码可以获取datagridview复选框单元格值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-13
      相关资源
      最近更新 更多