情景:Winform上有两个dataGridView:dataGridView1、dataGridView2,dataGridView1中有一个CheckBox列,选中多行后,点击界面上按钮【加入】,把选中的记录一次性加入到dataGridView2中。现状:当dataGridView2是和DataSet中某个Table绑定时,总是失败!!但是,如果dataGridView2没有数据绑定,而只是手动添加未绑定列,这样可以实现。 foreach (DataGridViewRow row in this.customersDataGridView.Rows)
{
if ( row.Cells[0].Value != null)
{
DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)row.Cells[0];
if ((bool)cbx.FormattedValue)
{
int rowIndex = this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[rowIndex].Cells[0].Value = row.Cells[2].Value;
this.dataGridView1.Rows[rowIndex].Cells[1].Value = row.Cells[3].Value;
this.dataGridView1.Rows[rowIndex].Cells[2].Value = row.Cells[4].Value;
this.dataGridView1.Rows[rowIndex].Cells[3].Value = row.Cells[5].Value; // 清除选择
row.Cells[0].Value = false;
}
}
}哪位老师可以帮忙实现有数据绑定的情况?谢谢了!!!!!!!!!!!
{
if ( row.Cells[0].Value != null)
{
DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)row.Cells[0];
if ((bool)cbx.FormattedValue)
{
int rowIndex = this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[rowIndex].Cells[0].Value = row.Cells[2].Value;
this.dataGridView1.Rows[rowIndex].Cells[1].Value = row.Cells[3].Value;
this.dataGridView1.Rows[rowIndex].Cells[2].Value = row.Cells[4].Value;
this.dataGridView1.Rows[rowIndex].Cells[3].Value = row.Cells[5].Value; // 清除选择
row.Cells[0].Value = false;
}
}
}哪位老师可以帮忙实现有数据绑定的情况?谢谢了!!!!!!!!!!!
http://blufiles.storage.live.com/y1p6PXvBt8cda68yiHRVjR0EyLI_eUVqPq5KAgcrzei5No20A2EuTzxPXzEQPJEJt9XMc4M7ejaIpk foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if ( row.Cells[0].Value != null)
{
DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)row.Cells[0];
if ((bool)cbx.FormattedValue)
{
int rowIndex = this.dataGridView2.Rows.Add();
this.dataGridView2.Rows[rowIndex].Cells[0].Value = row.Cells[2].Value;
this.dataGridView2.Rows[rowIndex].Cells[1].Value = row.Cells[3].Value;
this.dataGridView2.Rows[rowIndex].Cells[2].Value = row.Cells[4].Value;
this.dataGridView2.Rows[rowIndex].Cells[3].Value = row.Cells[5].Value; // 清除选择
row.Cells[0].Value = false;
}
}
}
2 根据GridView1中选中的索引 e.Item.Cells[0].Text,在GridView2中动态绑定相关表中的记录
將DataGridView1中選中的數據存入DataSet中某个Table中,然後將DataGridView2綁定Table
直接對Table操作,不要手動給DataGridView2添加行