Datagridview 行复制的问题,在线等
我有两个datagridview(dg1和dg2),dg1有3天记录 ,dg2没有记录
当我双击 dg1的第二条记录的时候
dg2就添加了第二条记录
请问怎么做?
谢谢。
[解决办法]
去grid1的currentrow,grid2.Rows.Add,然后将每个cell的值添加到grid2的新行中
[解决办法]
public void DataBin()
{
//dataGridView1
if (dataGridView1.Rows.Count > 0) { dataGridView1.Rows.Clear(); }
dataGridView1.Rows.Add();
dataGridView1.Rows[dataGridView1.NewRowIndex + 1].Cells[0].Value = "1";
dataGridView1.Rows[dataGridView1.NewRowIndex + 1].Cells[1].Value = "刘老根";
dataGridView1.Rows[dataGridView1.NewRowIndex + 1].Cells[2].Value = "男";
dataGridView1.Rows[dataGridView1.NewRowIndex + 1].Cells[3].Value = "12580";
dataGridView1.Rows[dataGridView1.NewRowIndex + 1].Cells[4].Value = "亚洲中国";
dataGridView1.Rows.Add();
dataGridView1.Rows[dataGridView1.NewRowIndex + 2].Cells[0].Value = "2";
dataGridView1.Rows[dataGridView1.NewRowIndex + 2].Cells[1].Value = "郭德纲";
dataGridView1.Rows[dataGridView1.NewRowIndex + 2].Cells[2].Value = "男";
dataGridView1.Rows[dataGridView1.NewRowIndex + 2].Cells[3].Value = "10086";
dataGridView1.Rows[dataGridView1.NewRowIndex + 2].Cells[4].Value = "中国北方";
dataGridView1.Rows.Add();
dataGridView1.Rows[dataGridView1.NewRowIndex + 3].Cells[0].Value = "3";
dataGridView1.Rows[dataGridView1.NewRowIndex + 3].Cells[1].Value = "周立波";
dataGridView1.Rows[dataGridView1.NewRowIndex + 3].Cells[2].Value = "男";
dataGridView1.Rows[dataGridView1.NewRowIndex + 3].Cells[3].Value = "10010";
dataGridView1.Rows[dataGridView1.NewRowIndex + 3].Cells[4].Value = "中国南方";
}
private void Form2_Load(object sender, EventArgs e)
{
DataBin();
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow row = (DataGridViewRow)this.dataGridView1.Rows[e.RowIndex].Clone();
row = dataGridView1.CurrentRow;
dgv2_databin(row);
}
private void dgv2_databin(DataGridViewRow row)
{
dataGridView2.Rows.Add();
dataGridView2.Rows[dataGridView2.NewRowIndex + dataGridView2.Rows.Count].Cells[0].Value = row.Cells[0].Value.ToString();
dataGridView2.Rows[dataGridView2.NewRowIndex + dataGridView2.Rows.Count].Cells[1].Value = row.Cells[1].Value.ToString();
dataGridView2.Rows[dataGridView2.NewRowIndex + dataGridView2.Rows.Count].Cells[2].Value = row.Cells[2].Value.ToString();
dataGridView2.Rows[dataGridView2.NewRowIndex + dataGridView2.Rows.Count].Cells[3].Value = row.Cells[3].Value.ToString();
dataGridView2.Rows[dataGridView2.NewRowIndex + dataGridView2.Rows.Count].Cells[4].Value = row.Cells[4].Value.ToString();
}