tags:

views:

19

answers:

1

I have this requierements that if a click a particular cell on datagrid view..it will copy the cell string and display on a textbox on the other form.

    This is my PseodoCode:

    Example:

    1.Display Datagrid View

    Name  | Family  |
    Boar  | Mamals  | 
    Snake | Reptile |  

    2.If Snake Clicked on Datagrid View.
    3.Then Copy Snake string
    4.Show Form2 then Display Snake on Textbox

Is this Possible Thanks in Regards!

A: 

Here it goes Form1 is your main form with grid called dataGridView1

private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
    string x = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].FormattedValue.ToString();
    Form2 myForm = new Form2();
    myForm.y = x;
    myForm.ShowDialog();
}

Form2 is secondary form to display item

public partial class Form2 : Form
{
    public string y = string.Empty;
    public Form2()
    {
        InitializeComponent();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        textBox1.Text = y;
    }
}
Raymund
Thanks it works Smoothly!
Crimsonland