DataGridViewTextBoxCell到DataGridViewTextBoxCell变换出错
DataGridViewTextBoxCell到DataGridViewTextBoxCell转换出错
DataGridViewCheckBoxCell MycheckBoxCell = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells["ustate"];
这一句报错
无法将类型为“System.Windows.Forms.DataGridViewTextBoxCell”的对象强制转换为类型“System.Windows.Forms.DataGridViewCheckBoxCell”
不知道是怎么回事
------解决方案--------------------
类型不一致
DataGridViewTextBoxCell MyCell = (DataGridViewTextBoxCell)dataGridView1.Rows[i].Cells["ustate"];
- C# code
dataGridView1.DataSource = ds.Tables["user_info"].DefaultView; for (int i = 0; i < dataGridView1.Rows.Count; i++) { DataGridViewCheckBoxCell MycheckBoxCell = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells["ustate"]; if (Convert.ToBoolean(dataGridView1.Rows[i].Cells["ustate"].Value)) { MycheckBoxCell.Value = true; } }
DataGridViewCheckBoxCell MycheckBoxCell = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells["ustate"];
这一句报错
无法将类型为“System.Windows.Forms.DataGridViewTextBoxCell”的对象强制转换为类型“System.Windows.Forms.DataGridViewCheckBoxCell”
不知道是怎么回事
------解决方案--------------------
类型不一致
DataGridViewTextBoxCell MyCell = (DataGridViewTextBoxCell)dataGridView1.Rows[i].Cells["ustate"];