hi guys just wanted to ask for help about creating a for loop that will cover all the textboxes inside a form. There are no panels in my form by the way, all textboxes are in a single form. Now what I want to do is like create a for loop for it and for example a textbox is not filled up with info (ex. Textbox_Address) when you click the Save_Information button, it will automatically detect that the Textbox_Address is empty and right after clicking Save_Information button it will display a messagebox saying: "Address Textbox is empty, please fill up the necessary details for that textbox". Same goes with the other textboxes which are not yet filled, Example all the textboxes are already filled up but the last two textboxes were left blank and let's say this last two textboxes are named Textbox_A and Textbox_B. The loop will scan all the textboxes until it gets to the last two empty textboxes and then will it display a message box notifying the user that they are empty right after clicking the Save_Information button. anyone here who can help me guys please I need to know how... Thank you for those who will help me out. God Bless you all.

hi king03
you can use foreach loop to check all textboxes(or any type of objectes) for compare them for example to 'A'

of course you can use for each and for loop and get textboxes.

One way would be iterating through all controls on the form, checking if its a textbox and then checking if its blank. Something like

foreach (Control cl in this.Controls)
            {
                if (cl is TextBox)
                {
                    if (cl.Text.Trim() == String.Empty)
                    {
                        MessageBox.Show("Please fill all textboxes");
                        break;
                    }
                }
            }

Makes sense ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.