Check if TextBox is empty and return MessageBox?

后端 未结 8 1372
谎友^
谎友^ 2020-12-23 22:19

I made this statement to check if TextBox is empty, but the MessageBox always shows up wether the TextBox is empty or not.

    private void NextButton_Click         


        
8条回答
  •  长情又很酷
    2020-12-23 22:44

    Well, you are clearing the textbox right before you check if it's empty

    /* !! This clears the textbox BEFORE you check if it's empty */
    MaterialTextBox.Clear();
    
    HoursNumericUpDown.Value = HoursNumericUpDown.Minimum;
    MarkNumericUpDown.Value = MarkNumericUpDown.Minimum;
    
    if (String.IsNullOrEmpty(MaterialTextBox.Text))
    {
            MessageBox.Show("Enter Material Name Please.", "Error", MessageBoxButtons.OK,    MessageBoxIcon.Warning);
                //dataGridView1.Rows.Clear();
    }
    

提交回复
热议问题