Standardized US States Array and Countries Array

后端 未结 9 1741
再見小時候
再見小時候 2020-12-09 16:33

Does anyone know of a nice, usable class that everyone on here could benefit from to use in populating the ComboBox controls on a form for the Country and State

9条回答
  •  遥遥无期
    2020-12-09 17:33

    Countries, and states within them come and go more frequently than you'd think around the world, and so hard coding them is not the best idea. It's best to get them both dynamically. Otherwise you're going to have to update your program every time there's a political change anywhere in the world. Further, from a software design perspective, political boundaries are data sets of significant size, and therefore putting them in a database instead of in your code should be the default choice.

    If you can't pull from a web location, you should still be able to setup your code so that the data is stored somewhat-separately and pulled in dynamically it's therefore easier to update from a list.

    There are ISO Standards for both, ISO_3166-1 for countries and ISO_3166-2 for country's administrative subdivisions (states/provinces), however they charge for ongoing access to their lists. There's also geonames.org which is free and what I'd therefore recommend to start with. Ideally you'll want a database which regularly updates from one of these sources, and then pull in the information from there.

    There is a programmatic work-around for countries as in this SO answer: List of All Countries DropDown. However you'll notice that Regions do not map perfectly to countries, and therefore you'll have non-country regions like "Carribbean" in your results.

提交回复
热议问题