1

I have a form which contains infinite number of options which user and add. Some options are in textbox, and some are in combobox(selected is the value to be extracted).

The form is in a way that user can add as many combo box and text box he wants and let him write those information onto XML.

How do I code that in c#? If anyone can give me a short example of one each which loops through each added combo box and text box, that would be great.

Thank you in advance.

1
  • Won't that take the user an infinite amount of time? ;)
    – TrueWill
    Jun 19, 2011 at 4:12

1 Answer 1

2

You can iterate through all controls inside a form like this.

foreach(Control control in this.Controls)
{
    //here 'this' is representing the form you want to iterate through

    //you can check whether it is a combobox or a text box
    if(control.GetType() == typeof(Combobox))
    {
        //this is a combo box
    }
    else if(control.GetType() == typeof(Textbox))
    {
        //this is a text box
    }
}

using above method you will find the controls inside a particular form. After that you can write information in a XML file

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.