Error calling the form screen

0

I'm having trouble loading a menu through another screen and following my code below. What would be a possible solution for such an error?

public partial class frmMenu : Form
{
    public frmMenu()
    {
        InitializeComponent();
    }
    private void guichesToolStripMenuItem_Click(object sender, EventArgs e)
    {
        frmCadastroGuiche frm = new frmCadastroGuiche();
        frm.ShowDialog();
    }
}

Screen that should be loaded when you click the button on the guiche.

public partial class frmCadastroGuiche : Form
{
    public frmCadastroGuiche()
    {
        carregarCombos();
        carregando = true;
        carregargrid();
        carregando = false;
        InitializeComponent();
    }
    bool pularFiltro = false;
    bool carregando = false;
    public bool setDatabase(Sele.Classes.clsDatabase oDB)
    {
        try
        {
            oAtende.oDB = oDB;
            carregarCombos();
            carregando = true;
            carregargrid();
            carregando = false;
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }
    DataTable dtGuiche = new DataTable();
    public void carregarCombos()
    {
        lstTipoSenha_id.DataSource = oAtende.dtTipoSenha;
        oAtende.dtTipoSenha = oAtende.getSenhaTipo();
        lstTipoSenha_id.DisplayMember = "Tipo da Senha";
        lstTipoSenha_id.ValueMember = "id";
        lstTipoSenha_id.DataSource = oAtende.dtTipoSenha;
    }    
    private void carregargrid()
    {
        carregando = true;
        dg.CurrentCell = null;
        dg.AutoGenerateColumns = false;

        dtGuiche = oAtende.getGuiches("");
        dg.DataSource = dtGuiche.DefaultView;

        dg.CurrentCell = null;

        dg.ClearSelection();
        carregando = false;
    }
}

Below this would have the codes of the save and delete buttons in the fields that were passed, but I did not put it because I did not find it necessary I believe the error is not there.     

asked by anonymous 07.04.2017 / 19:03

1 answer

2

There is some exception going on and you can not see it.

The InitializeComponents() method needs to be called before any interaction with the screen components, because it is this method that creates them .

The constructor should be this way

public frmCadastroGuiche()
{        
    InitializeComponent();
    carregarCombos();
    carregando = true;
    carregargrid();
    carregando = false;
}
    
07.04.2017 / 19:22