Click here to Skip to main content
15,038,848 members
Please Sign up or sign in to vote.
1.57/5 (3 votes)
See more:
Hi ,
I want to use States and cities of USA in listview. How i can add them all. as there are hundred of them.
Anyone can please provide me the list in c# file of USA states and cities so that i can add it.
Or how i can add all of them.

Need Help
Shan Khan
Posted
Updated 23-Mar-21 12:33pm

1 solution

Here is a states dictionary:

public string stateAbbreviationExpand(string abbr)
{
Dictionary<string,> states = new Dictionary<string,>();

states.Add("AL", "Alabama");
states.Add("AK", "Alaska");
states.Add("AZ", "Arizona");
states.Add("AR", "Arkansas");
states.Add("CA", "California");
states.Add("CO", "Colorado");
states.Add("CT", "Connecticut");
states.Add("DE", "Delaware");
states.Add("DC", "District of Columbia");
states.Add("FL", "Florida");
states.Add("GA", "Georgia");
states.Add("HI", "Hawaii");
states.Add("ID", "Idaho");
states.Add("IL", "Illinois");
states.Add("IN", "Indiana");
states.Add("IA", "Iowa");
states.Add("KS", "Kansas");
states.Add("KY", "Kentucky");
states.Add("LA", "Louisiana");
states.Add("ME", "Maine");
states.Add("MD", "Maryland");
states.Add("MA", "Massachusetts");
states.Add("MI", "Michigan");
states.Add("MN", "Minnesota");
states.Add("MS", "Mississippi");
states.Add("MO", "Missouri");
states.Add("MT", "Montana");
states.Add("NE", "Nebraska");
states.Add("NV", "Nevada");
states.Add("NH", "New Hampshire");
states.Add("NJ", "New Jersey");
states.Add("NM", "New Mexico");
states.Add("NY", "New York");
states.Add("NC", "North Carolina");
states.Add("ND", "North Dakota");
states.Add("OH", "Ohio");
states.Add("OK", "Oklahoma");
states.Add("OR", "Oregon");
states.Add("PA", "Pennsylvania");
states.Add("RI", "Rhode Island");
states.Add("SC", "South Carolina");
states.Add("SD", "South Dakota");
states.Add("TN", "Tennessee");
states.Add("TX", "Texas");
states.Add("UT", "Utah");
states.Add("VT", "Vermont");
states.Add("VA", "Virginia");
states.Add("WA", "Washington");
states.Add("WV", "West Virginia");
states.Add("WI", "Wisconsin");
states.Add("WY", "Wyoming");
if (states.ContainsKey(abbr))
return (states[abbr]);
/* error handler is to return an empty string rather than throwing an exception */
return "";
}

You can add the cities in a dictionary tree likewise
   
Comments
shanalikhan 12-Apr-13 6:52am
   
there are many cities , do i have to manually add the cities ? it will take alot of time . is there any 3rd party tool which will provide me the cities with respoect to states
tumbledDown2earth 12-Apr-13 7:13am
   
you can get a datafile dump from here:
http://www.codeproject.com/Questions/154877/Need-database-for-all-countries-state-city

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900