for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value) == true)
                {checkbox已用            DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();
            newColumn.HeaderText = "this.studentDataSet2._Sheet1_";
            dataGridView1.Columns.Add(newColumn)  生成
出现对象不能从 DBNull 转换为其他类型  。请问怎么解决

解决方案 »

  1.   

       
    应该这样写,你那肯定不正确.  string _selectValue = dgvtable.Rows[i].Cells[0].EditedFormattedValue.ToString();       if (_selectValue == "True") //选中的复选框
                    {
                                      }
      

  2.   

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[0];
                    if ((Boolean)chk.EditedFormattedValue == true)
                    {
                        dataGridView1.Rows[i].Cells[0].Value = false;
                    }
                    else
                        dataGridView1.Rows[i].Cells[0].Value = true;
                }
      

  3.   

    DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[0];先转换,再取值,楼上正确