0

I hav 2 datagrid one named dgvflag and another named dgvflag1
There r some rows in dgvflag
wen i select one of d row n click on add button dat row should b added to another datagrid named dgvflag1
plzzz help i need code 4 dis urgently
thnxx in advance

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by Mitja Bonca
1

Hi,
1st, point is that you have the same columns, ok its not really necessary, but its good when you want to copy a row from on dataGrid to anoter to have at least the same number of columns and that are the same type (even all can be parsed as objects).
So this is the code example:

private void button1_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                dataGridView2.Rows.Add();
                int newRow = dataGridView2.Rows.Count - 1;
                foreach (DataGridViewCell cell in row.Cells)
                {
                    dataGridView2[cell.ColumnIndex, newRow].Value = cell.Value;
                }
            }
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.