Communicate child form with parent

1

I am working on a windows forms app in which I want to communicate a child form with a parent form. The implementation that I have for this purpose is the following:

Interface

public interface IActualizarDGVPrincipal
{
    void AcualizarDGV();
}

This interface is implemented in the parent form, which becomes my MDI form.

The method is called from the child form, which is a user control:

public IActualizarDGVPrincipal Opener { get; set; }

private void Actualizar()
    {
        Opener.AcualizarDGV();        
    }

At the moment of calling the method, it gives me an error of reference to an object not established as an instance of an object.

I am using ninject, and I call the son formulrio from the father as follows:

private void btnMenuCategoria_Click(object sender, EventArgs e)
    {
        ActivarTitulos(true, strSubCategoria.nameEntity);
        var argCall = new ConstructorArgument("this", this);

        var categoria = CompositionRoot.Resolve<ucCategoria>(argCall);
        categoria.DGVCategoria += Categoria_DGVCategoria;
        categoria.DGVSubCategoria += Categoria_DGVSubCategoria;
        categoria.CategoriaClose += Categoria_CategoriaClose;
        this.CurrentControl = categoria;

        CargarDGVPrincipal(AsignacionTablas.SubCategoria);
    }

That's where I must pass the instanced parameter to have no problems in the child form when I call it. Any suggestions to solve it?

    
asked by Pedro Ávila 20.06.2016 в 20:44
source

1 answer

0

I solved it in the following way:

private void btnMenuCategoria_Click(object sender, EventArgs e)
{
    ActivarTitulos(true, strSubCategoria.nameEntity);
    var categoria = CompositionRoot.Resolve<ucCategoria>();
    *categoria.Opener = this; ==> Esto era todo.*
    categoria.DGVCategoria += Categoria_DGVCategoria;
    categoria.DGVSubCategoria += Categoria_DGVSubCategoria;
    categoria.CategoriaClose += Categoria_CategoriaClose;
    this.CurrentControl = categoria;

    CargarDGVPrincipal(AsignacionTablas.SubCategoria);
}
    
answered by 20.06.2016 / 21:22
source