Pass Selection of a DataGridView to another form

0

I am working on the CellContentDoubleClick of my DataGridView

Entradademercancia frm = new Entradademercancia();
        frm.txtrnc.Text = dtgv.CurrentRow.Cells[0].Value.ToString();
        frm.btnbuscar.Select();
        this.Hide();

the code works but only the% share This.Hide(); that is, the value that must be sent does not reach the other form and does not indicate any error.

    
asked by Samuel Ignacio Susana Confesor 11.12.2018 в 18:33
source

1 answer

1

There is an important concept that needs to be understood. The forms are objects.

This means that it does not matter that they have something visual, they are objects and they are handled with instances like all other objects.

That is ...

If you had an animal class, and did the following:

private void funcion1()
{
   animal uno = new animal();
   ....
}

private void funcion2()
{
   animal uno = new animal();
   ....
}

The two variables one, do not represent the same animal. They represent different animals (objects).

And the same goes for the form. The problem is to think that because it has a visual component, the program knows that it exists.

private void funcion1()
{
   form uno = new formloquesea();
   ....
}

private void funcion2()
{
   form uno = new formloquesea();
   ....
}

The two variables one, are not the same form. So, if we want to know which form is in one, we have to save that form somewhere.

In your case, if you have already raised the form Entranceofmercentage, it is important that you understand that when in any other part of your code you do

Entradademercancia frm = new Entradademercancia();

It's ANOTHER new form, even if the variable is the same and the form is of the same class.

What you have to do, is when you raise the search form, pass a reference to this, so you know who the form is that I call it. and in that way, you will be able to return things.

    
answered by 12.12.2018 / 02:31
source