2
Reply

How take elements from one form and add them on a datagrid on another form?

John Beeman

John Beeman

Aug 13 2008 2:33 PM
2.6k
I am trying to take selected rows of datagrid on Form2 and add them to a datagrid on Form1. I am new to C# forms and I am having trouble thinking of the approach to take. As I understand, it is bad practice to make public variables accessible from any form, so it would be nice to do it the right way.

I have a button press on Form2 that I want to trigger copying the selected rows from a datagrid on Form2 to a datagrid on Form1. Can anyone tell me the best approach for this?


Form2:

private void button4_Click(object sender, EventArgs e) //button to copy rows from Form2 datagrid to Form1 datagrid
        {
            for (int i = 0; i < dataGridView1.SelectedRows.Count; i++) //Form2 datagrid
            {
                   //Copy these elements to Form1 and add them onto Form1 datagrid

            }
        }

Thanks,
John

Answers (2)