How can I reload a datagridview from another form?

0

I have the following problem with my project:

I have a form 1 where I see tickets that took turns.

When I click on call once the record is selected, it saves the information inside a table.

This other form raises the information at the start of that grid:

My question would be, how can I update the table in form 2 every time I insert data from form 1?

Thanks in advance.

UPDATE.

I have tried with what they mentioned to use a method from form 2 and invoke it and use it in the one, but I still do not get results, the method works since when I use it in form 2 with a Load it just raises, it brings all the data, but when in form 1 I add it to the click-to-call event, it does not update the grid of form 2, if I close it and lift it up again if it brings them. It is necessary that the form 2 always remains open, so it is impossible to close it and open it for each time you need to update the data.

Greetings!

Code in form 2:

public partial class Llamador : Form
{
    public Llamador()
    {
        InitializeComponent();
    }

    Controles con = new Controles();

    public void UpdatearCosas()
    {
        con.CargarTurnosLlamados(dgvLlamador);
    }

'

And this is the code of form 1 invoking the method created before.

'

    private void btnLlamar_Click(object sender, EventArgs e)
    {
        Controles con = new Controles();

        TurnosLlamados turnosallamar = new TurnosLlamados();

        int idserv = Convert.ToInt32(cmbServicio.SelectedValue);

        turnosallamar.Id_Puesto = Convert.ToInt32(cmbPuestos.SelectedValue);

        turnosallamar.NroTurno = Convert.ToInt32(this.dgvTurnos.CurrentRow.Cells[1].Value);

        con.LlamarTurno(turnosallamar);

        int id = Convert.ToInt32(this.dgvTurnos.CurrentRow.Cells[0].Value);

        con.CambiarEstado(id);
        con.cargargrillaTurnos(dgvTurnos, idserv);
        Llamador llama = new Llamador();
        llama.UpdatearCosas();
    }

But the method still does not work.

    
asked by Gustavo Alexis 19.11.2018 в 17:42
source

1 answer

0

What you want to do is right, but it's wrong.

The form is just another object. And like every object, it has instances.

The form , is a particular object since in addition to properties and methods, it "draws". But that does not make it not work like a common object.

Then, when you do this:

Llamador llama = new Llamador();
llama.UpdatearCosas();

It's wrong, because definitely, that new form , is not the same as you're showing on the screen.

What you have to do is call the method UpdatearCosas , but the form that you opened at the time.

    
answered by 20.11.2018 в 14:01