locked
How do I display the contents of a TextBox inside a MessageBox? RRS feed

  • Question


  • I am developing a C# / SQL WinForms solution in VS 2015 and I'm a newbie.

    I am trying to display the text of a textBox inside a MessageBox, but my code is not working. Can you please take a look at it and tell me what's wrong? I'd really appreciate it. Thank you! Best regards. :)

    private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("Tem certeza que deseja excluir o pagamento " + cod_caixaTextBox.Text, "Atenção", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                {
                    this.caixaBindingSource.EndEdit();
                    this.tableAdapterManager.UpdateAll(this.bremingtonBackEndDataSet);
                    MessageBox.Show("Pagamento excluido com sucesso!", "Pronto ...", MessageBoxButtons.OK);
                }
                else
                {
                    caixaBindingSource.CancelEdit();
                    this.caixaTableAdapter.Fill(this.bremingtonBackEndDataSet.caixa);
                }
            }


    jcrcarmo

    Friday, October 14, 2016 3:06 AM

Answers

  • PROBLEM SOLVED!!!  All I had to do was set the BindingNavigator DeleteItem property to NONE to handle the delete action manually, thus bypassing the built-in delete action.  Now that the record is not being automatically deleted when I click the delete button in the navigator, the textbox text magically appears in the MessageBox.

    jcrcarmo

    • Marked as answer by JC Carmo Friday, October 14, 2016 5:46 AM
    Friday, October 14, 2016 5:46 AM

All replies

  • hi Jc Carmo,

    simple way to display text of texybox in MessageBox is

    MessageBox.Show(textbox1.Text);

    please vote if this was helpful

    Friday, October 14, 2016 3:37 AM
  • I found the problem: My synthax is correct, but the reason why the contents of the TextBox are not displayed in the MessageBox is because when I click on the BindingNavigatorDeleteItem, it deletes the record without confirmation, thus the MessageBox can't display the TextBox.Text because it has been deleted. Now I have to find a way to add the confirmation BEFORE the BindingNavigatorDeleteItem deletes the record. Any ideas?


    jcrcarmo

    Friday, October 14, 2016 3:46 AM
  • It seems that you would have a button to do the delete, and in the button's click-event, you do the confirmation. The Delete button makes the call to do the delete.

    Hey, it's a thought.

    Friday, October 14, 2016 4:45 AM
  • PROBLEM SOLVED!!!  All I had to do was set the BindingNavigator DeleteItem property to NONE to handle the delete action manually, thus bypassing the built-in delete action.  Now that the record is not being automatically deleted when I click the delete button in the navigator, the textbox text magically appears in the MessageBox.

    jcrcarmo

    • Marked as answer by JC Carmo Friday, October 14, 2016 5:46 AM
    Friday, October 14, 2016 5:46 AM