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

Monday, January 2, 2012

Save and Read Combo Box Items from an XML File

Introduction
When discussing file processing, we mentioned that it is sometimes necessary to automatically save a file when an application exits, without any intervention from the user. You can also solve this exact problem using XML. The ever growing strength of XML is in its ability to let modify a file however but still make that file usable by any environment that needs its content.

We are going to create an XML file that holds a list of items for a combo box. Once the file exists, it can be processed or modified by any application that can read XML. We will load the file automatically when the application opens and retrieve the values of the elements to complete a combo box. While using the application, we will allow the user to change the list. When the application closes, we will retrieve the list of items from the combo box and update (in reality) recreate the list that includes the new items.

Practical Learning: Using XML Values


1. Related link:Start Visual C# and create a new Windows Forms Application named XmlListUpdate1
2. To create an XML file, on the main menu, click Project -> Add New Item...
3. In the Templates list, click XML File (.xml)
4. In the Name box, replace the string with ISFlavors and click open
5. Change the contents of the file as follows:
6. Save this XML file in your bin\Debug folder
7. Design the form as follows:








http://www.functionx.com/vcsharp2003/xml/comboboxitems.htm