How to copy selected row gridView to another Dexexpress?

95 views Asked by At

I want to copy selected row in gridView1/gridControl1 to gridView2/gridControl2, gridView1 with DataSource and DataTable:

private void chon2_Click(object sender, EventArgs e)
{
    for (int i = 0; i < gridView1.GetSelectedRows().Length; i++)
                {
                    gridView2.AddNewRow();
                    gridView2.SetRowCellValue(i, "column2",gridView1.GetRowCellValue(i, "colum1").ToString());
                }
}

But it does not work

1

There are 1 answers

0
George On

I can see that you are trying to set the row cell value within the _Click event. This won't work. You need to set the row cell value(s) behind the _InitNewRow event.

Try the following:

Behind the _Click event, add the following line:

private void chon2_Click(object sender, EventArgs e) 
{          
    gridView.AddNewRow(); 
}

Create a _InitNewRow event via GridView > Events and you should have something that looks like this:

private void gridView_InitNewRow(object sender, InitNewRowEventArgs e) 
{ 

}

To set the value(s), add the following:

private void gridView_InitNewRow(object sender, InitNewRowEventArgs e) 
{
    gridView.SetRowCellValue(e.RowHandle, "FieldName1", value1);
    gridView.SetRowCellValue(e.RowHandle, "FieldName2", value2);
    gridView.SetRowCellValue(e.RowHandle, "FieldName3", value3);
}