读书人

DataGridView 绑定了DataTable 数据 小

发布时间: 2013-10-22 16:17:03 作者: rapoo

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); //这里一直报错

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

读书人网 >C#

热点推荐