首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

DataGridViewTextBoxCell到DataGridViewTextBoxCell变换出错

2012-08-27 
DataGridViewTextBoxCell到DataGridViewTextBoxCell转换出错C# code dataGridView1.DataSource ds.Table

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"];

热点排行