日期:2014-05-18  浏览次数:21248 次

DataGridViewTextBoxCell到DataGridViewTextBoxCell转换出错
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"];