Wednesday, January 4, 2012

Extract values from vary controls and Write it on XML

This has found in forum who shared the problem and solution as mentioned above title.
Background:
A form contains many controls, such as TextBox, ComboBox and etc...
Then, we need to extract the value from these options.

The code example is as below:

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
    }
}
This is a nice example as for beginner like me ^^/
Link: http://stackoverflow.com/questions/6400382/how-do-i-extract-values-from-controls-and-write-it-on-xml

No comments: