Form closing without close()

Asked

Viewed 83 times

4

Dear friends, I have a very simple form that is closing after clicking OK on Messagebox. I have already reviewed everything, compared it with other papers I have and I haven’t found the solution. If anyone can give me a hand, Thank you.

namespace menu
{
    public partial class frmFinanceiroDocumentosVencidosGrid : Form
    {
        public frmFinanceiroDocumentosVencidosGrid()
        {
            InitializeComponent();
        }



        public int codigo { get; set; }


        private void frmFinanceiroDocumentosVencidosGrid_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = ClienteBLL.verificaParcelasVencidas(codigo);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void btnVisualizar_documento_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count > 0)
            {
                int codigo = (int)dataGridView1.CurrentRow.Cells[0].Value;
                Financeiro fin = FinanceiroBLL.pesquisaFinanceiroCodigo(codigo);
                if (fin.nota_fiscal_id != null)
                {
                    int nota_codigo = (int)fin.nota_fiscal_id;
                    using (frmNotaFiscalVisualizar ver = new frmNotaFiscalVisualizar())
                    {
                        ver.codigo = nota_codigo;
                        ver.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("Não há notas fiscais vinculadas à este documento.");
                }
            }
        }

        private void btnFechar_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
  • What is the code of the form frmNotaFiscalVisualizar?

  • What are you calling this Form?

2 answers

2

Check the value of the property DialogResult of the button, it must have as value DialogResult.None.

Another detail, the form has two properties AcceptButton and CancelButton check that the button you are clicking is not selected in these properties.

0

may be happening some error or untreated Exception, you may try putting a Try/catch to test

private void btnVisualizar_documento_Click(object sender, EventArgs e)
{
    try
    {
        if (dataGridView1.Rows.Count > 0)
        {
            int codigo = (int)dataGridView1.CurrentRow.Cells[0].Value;
            Financeiro fin = FinanceiroBLL.pesquisaFinanceiroCodigo(codigo);
            if (fin.nota_fiscal_id != null)
            {
                int nota_codigo = (int)fin.nota_fiscal_id;
                using (frmNotaFiscalVisualizar ver = new frmNotaFiscalVisualizar())
                {
                    ver.codigo = nota_codigo;
                    ver.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("Não há notas fiscais vinculadas à este documento.");
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

Browser other questions tagged

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