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

DataGridView 绑定了DataTable 数据 小弟我加了一列DataGridViewCheckBoxColumn 怎么根据选中的生成新的DT

2013-10-22 
DataGridView 绑定了DataTable 数据 我加了一列DataGridViewCheckBoxColumn 如何根据选中的生成新的DTData

DataGridView 绑定了DataTable 数据 我加了一列DataGridViewCheckBoxColumn 如何根据选中的生成新的DT
DataGridView 绑定了DataTable 数据 比如有10列 我只显示其中5列 设定了AutoGenerateColumns = false;

第一列加了DataGridViewCheckBoxColumn  让客户勾选选择想要的数据

问题是如何根据选中记录的生成新的DT


                DataSet newds = new DataSet();
                DataTable dt = oldds.Tables[0].Clone();

                foreach (DataGridViewRow row in this.dgvViewRow.Rows)
                {
                    if ((bool)row.Cells["colCheck"].Value) // 如果是选中
                    {
                        dt.Rows.Add((row.DataBoundItem as DataRowView)); //这里一直报错
                    }
                }
 
[解决办法]
           dgvUserManag.DataSource = dtUser;         
            DataTable dt = dtUser.Clone();
            foreach (DataGridViewRow row in this.dgvUserManag.Rows)
            {
                Boolean chk = Boolean.Parse(dgvUserManag.Rows[i].Cells[0].EditedFormattedValue.ToString());

                if (chk) // 如果是选中
                {
                    
                    dt.Rows.Add((row.DataBoundItem as DataRowView).Row.ItemArray); //这里一直报错

                }
            }
百度报错的内容,找解决方案

热点排行