I have a datagrid in a window.

If I double click, I need to show the selected row in text boxes in a new window.

When I double click a row, I can display the new form right now.

How can I know what row was double clicked in the new window..

I cannot find a way for my "form2", which is the new window, to have access to the datagrid which sent it...

How can the form2 know..

What "topics" should I read to understand this? Is this related to Data Binding?


Was it helpful?


define an event handler for CellDoubleClick or CellContentDoubleClick. In the event handler function do this.

    private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    DataGridViewRow row = (DataGridViewRow) sender; //cast the sender object to DataGridViewRow
    Form2 newForm = new Form2(row);

and in the Form2 constructor

    public class Form2 : Forms
       private DataGridViewRow _row;

    public Form2(DataGridView row)
        _row = row; // now you have a copy of the row in question
        txtFname.Text = _row.Cells[0].ToString(); 
        //row.Cells[0], row.Cells[1], row.Cells[n] will work here
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow