Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Function Problem - Check empty textboxes

$
0
0

Hello, i've a problem with this function. Error = errorProvider

  public bool IsEmpty { get; set; }

public void CheckEmpty(List<TextBox> txt)
        {
            foreach (TextBox t in txt)
            {

                if (t.Text == string.Empty)
                {
                    IsEmpty = true;
                    error.SetError(t, "Error");
                }

                else
                {
                    error.Clear();

                }

            }

            if (IsEmpty == true)
            {
                MessageBox.Show("Eror!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


        private void button2_Click(object sender, EventArgs e)
        {
            List<TextBox> txt = new List<TextBox>() { textBox1, textBox2 };
            CheckIsEmptyPart(txt);

        }

Now, when I write some in textBox1 and texBox2 - is ok - no error. When textbox1 and textbox2 is empty - is ok, shows up Error Text, but now when I write some in textboxes - Icons errordisappear and shows up again Error Text,although textboxes doesn't empty. How can Ichange thefunction thatwas ok?

Thanks





Viewing all articles
Browse latest Browse all 12583

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>