【问题标题】:c# datagridview checkbox check if other column value is 0c#datagridview复选框检查其他列值是否为0
【发布时间】:2016-02-08 13:49:37
【问题描述】:

我有一个带有复选框列(标题:状态)和文本框列(标题:数量)的 DataGridView。如果数量为0,我想自动检查复选框列。

【问题讨论】:

  • @ethorn10 我只是一名学生..我的教授只教基本的 c#..我从 2015 年 11 月开始研究并尝试这个,但我做不到..这就是我在这里问的原因(对不起我的英语希望你能理解)

标签: c# checkbox datagridview


【解决方案1】:

如果 datagridview 像这样,则遍历行:

foreach (DataGridViewRow row in dataGridView1.Rows)
{
    //Check Column 3 for quantity        
    if (row.Cells[3].Value.ToString() == "0")
    {   
        //Get checkbox in column 1 and cast it to a checkbox
        DataGridViewCheckBoxCell cell = row.Cells[1] as DataGridViewCheckBoxCell;     
        cell.Value = cell.TrueValue;
    }
}

【讨论】:

  • 非常感谢您! cell.Value == cell.TrueValue 有错误;但我删除了一个=(等号)并且它有效..再次感谢.. :)
  • 先生..你知道如何将它保存到访问数据库中吗?在datagridview中选中的复选框,但没有保存到访问数据库中。我使用更新语句,但它没有工作
  • 当然我可以帮助你,但我需要查看你的代码。只需编辑您的问题并添加您的新代码,以便我查看。
猜你喜欢
  • 2011-05-15
  • 1970-01-01
  • 1970-01-01
  • 2013-12-25
  • 1970-01-01
  • 1970-01-01
  • 2012-12-13
  • 1970-01-01
  • 2020-02-04
相关资源
最近更新 更多