我有2个datagridview,想把第一个datagridview中选中的行,在第二个datagridview中显示。代码如何写 10
展开全部
private void button1_Click(object sender, EventArgs e)
{
if(this.dataGridView1.SelectedRows.Count==1)
{
this.dataGridView2.Rows.Add(1);
this.dataGridView2.Rows[this.dataGridView2.Rows.Count-1].Cells[0].Value = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
this.dataGridView2.Rows[this.dataGridView2.Rows.Count-1].Cells[1].Value = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
this.dataGridView1.Rows.Remove(this.dataGridView1.SelectedRows[0]);
}
}
private void Form3_Load(object sender, EventArgs e)
{
this.dataGridView1.Rows.Add(3);
for (int i = 0; i < 3;i++ )
{
this.dataGridView1.Rows[i].Cells[0].Value = i.ToString();
this.dataGridView1.Rows[i].Cells[1].Value = (i + 1).ToString();
}
}
{
if(this.dataGridView1.SelectedRows.Count==1)
{
this.dataGridView2.Rows.Add(1);
this.dataGridView2.Rows[this.dataGridView2.Rows.Count-1].Cells[0].Value = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
this.dataGridView2.Rows[this.dataGridView2.Rows.Count-1].Cells[1].Value = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
this.dataGridView1.Rows.Remove(this.dataGridView1.SelectedRows[0]);
}
}
private void Form3_Load(object sender, EventArgs e)
{
this.dataGridView1.Rows.Add(3);
for (int i = 0; i < 3;i++ )
{
this.dataGridView1.Rows[i].Cells[0].Value = i.ToString();
this.dataGridView1.Rows[i].Cells[1].Value = (i + 1).ToString();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询