Monday, January 2, 2012

Save and Read Combo Box Items from an XML File

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:

1 comment:

csharpnoob said...

Is this content finished? I am struggling to add back to a list once read in, having problems saving a table to a public table for some reason.