for (int i = 0; i <= datagridview.Rows.Count; i++)
            {
                bool ischecked = (bool)datagridview.Rows[i].Cells[0].FormattedValue;
                if (ischecked)
                {
                    MessageBox.Show("yes!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("no!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            } 为什么当我把鼠标放在datagridview的某行上的数据时候,该行的Cells[0]的checkbox不管选中与否都被判断为"未选中"?

解决方案 »

  1.   


    for (int i = 0; i <= datagridview.Rows.Count; i++)
                {
                    bool ischecked = (bool)datagridview.Rows[i].Cells[0].Value;
                    if (ischecked)
                    {
                        MessageBox.Show("yes!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("no!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                } 
      

  2.   

    该行:bool ischecked = (bool)datagridview.Rows[i].Cells[0].Value;
    出错提示:未将对象引用设置到对象的实例。
      

  3.   

    bool ischecked = (bool)datagridview.Rows[i].Cells[0].Value; 
    有convert转换一下
      

  4.   

    DataGridView.EndEdit () ;
    结束编辑状态就可以了!