November 14, 2008 at 12:18 am
Hi Everyone
Can you please give me a sample code of copying one row from a datagridview to another datagridview. By the way in mousedoubleclick event.
Thanks
Liele
November 15, 2008 at 1:10 am
hi,
The following code used with MouseDoubleClick event to copy a selected row from dataGridView1 to dataGridView2
private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
DataTable dtable = new DataTable();
//Add columns to the Table
dtable.Columns.Add("column1");
dtable.Columns.Add("column2");
dtable.Columns.Add("column3");
//create object to store cell value of row
object[] objrows = new object[3];
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dtable.NewRow();
objrows = dataGridView1.CurrentRow.Cells.Value.ToString();
}
//Assign object values to table rows
dtable.Rows.Add(objrows);
dataGridView2.DataSource = null;
dataGridView2.Columns.Clear();
dataGridView2.DataSource = dtable;
}
hope it helps:)
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply