Copy from datagridview and paste to second datagridview

Copy from datagridview and paste to second datagridview

Post by ing.Zec » Tue, 30 Oct 2007 09:17:39


I need usage possibility when I double click on any row in datagridview,
that row must be copied in second datagridview.
Any good link about that?!
 
 
 

Copy from datagridview and paste to second datagridview

Post by U29tIE5hdG » Tue, 30 Oct 2007 14:43:00


private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{

}

in cellclick event of firdt datagrid u need to right code to add add the
selected rows to secod datagridview.

 
 
 

Copy from datagridview and paste to second datagridview

Post by U29tIE5hdG » Tue, 30 Oct 2007 15:41:00


private void Form1_Load(object sender, EventArgs e)
{


foreach(DataGridViewColumn c1 in dataGridView1.Columns)
{
DataGridViewColumn c2 = (DataGridViewColumn)c1.Clone();

dataGridView2.Columns.Add(c2);
}
}


private void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
DataGridViewRow r2 =
(DataGridViewRow)dataGridView2.Rows[0].Clone();
int i=0;
foreach( DataGridViewCell cell in
dataGridView1.Rows[e.RowIndex].Cells)
{
r2.Cells[i].Value = cell.Value;
i++;
}
dataGridView2.Rows.Add(r2);
dataGridView2.Refresh();
}



try thsi one first oin pageload add columns from first too secord datagrid
and then

in CellContentClick event add row from first to secord datagridview.