My answer for (almost) everything: XML Serialization.
here's how I would do it for this simple scope:
1. Create an XML file (maybe by querying a database) that represents the
data you want.
it might look something like this:
<StateList>
<State abbrev="AK" name="Alaska" />
<State abbrev="AL" name="Alabama" />
<State abbrev="AR" name="Arkansas" />
...
</StateList>
2. infer a schema from the xml file using the xsd.exe util in the .NET
Framework SDK. note: check the options on xsd.exe to select the
code-generation language (VB or C#).
xsd.exe /c statelist.xml
3. Compile the generated code
4. Write your app that uses the generated classes. To populate the
instances, use xml serialization.
something like this:
System.IO.FileStream fs = new System.IO.FileStream(path,
System.IO.FileMode.Open);
System.Xml.Serialization.XmlSerializer s= new
System.Xml.Serialization.XmlSerializer(typeof(Stat eList));
StateList l= (StateList) s.Deserialize(fs);
fs.Close();
5. You then can bind this thing to a control, like a listbox.
If I am not mistaken, the databound controls require public properties, not
fields. The xsd.exe tool generates classes with public fields. You may
need to modify the generated classes, or take some other step to
workaround. The issue is discussed in more detail here:
http://msdn.microsoft.com/library/en...ml01202003.asp
An alternative workaround is shown here:
http://www.winisp.net/cheeso/srcview...=MorphArray.cs
-Dino
"Aamir" <gh*****@bigfoot.com> wrote in message
news:4a************************@posting.google.com ...
Hi,
Quick Question:
How to create a simple XML with US States list and read it into a
combo box.
Detail:
I am very new to Dot Net technology as well as xml.
I am building a desktop app in C# and need to populate the US States
list (AL, AR, .. WY) in a combo box. I could have done it by reading
from a table in SQL server but rather prefer to have that list saved
locally at client side as an xml and read it from there. what is the
simplest way to go about it, what should be the structure of xml
document and do i need schema also ?
thanks for any response
Aamir