Click here to Skip to main content
15,903,030 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi!

I have a form which has two datagrids.i want with a button to copy the selected rows
from one to another.

how can i do this???
Posted

i find this code :

C#
private void button1_Click(object sender, EventArgs e)
       {

           foreach (DataGridViewRow row in this.table1DataGridView.SelectedRows)
           {
               object[] rowData = new object[row.Cells.Count];
               for (int i = 0; i < rowData.Length; ++i)
               {
                   rowData[i] = row.Cells[i].Value;
               }
               this.copyDataGridView.Rows.Add(rowData);
           }
       }

but it throw an exception:

Additional information: Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.

is the code correct??what should i do?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900