Reputation: 1873
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.
Upvotes: 1
Views: 147
Reputation: 30097
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
Upvotes: 2