Error calling form screen

Asked

Viewed 138 times

0

I’m having trouble loading a menu through another screen follows my code below. What would be a possible solution, for such 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 clicking the Guiche button.

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 save and delete buttons in the fields that were passed, but I did not put because I did not find it necessary I believe that the error is not there.

  • 1

    What’s the matter?

  • This screen frmMenu I can load the screen frmRelatories(I did not put the code), but when I try to call the screen frmCadastroGuiche the button happens nothing, the compiler does not report any error.

1 answer

2

Is there an exception happening and you’re not seeing.

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

The builder should be like this

public frmCadastroGuiche()
{        
    InitializeComponent();
    carregarCombos();
    carregando = true;
    carregargrid();
    carregando = false;
}
  • I made this change but still the error persists, the button does not call frmCadastroGuiche, I created another button for the test and the error still continues

  • Man, is there a mistake in the methods carregarCombos() and/or carregarGrid(). You remove them and test them.

  • I created a third button and it is now calling the screen, but it gives this exception. An unhandled Exception of type 'System.Argumentexception' occurred in System.Windows.Forms.dll Additional information: Unable to connect to new display member. just in the public void method loadCombos()

  • 1

    Well, you already know what the mistake is and why. Good luck =D

  • As @jbueno pointed out, the constructor is being adjusted and only comment on the methods and see where the error is.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.