w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Winforms - Show Datagrid selection in different window

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

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.