简体   繁体   English

动态选择列表C#

[英]Dynamic Select lists C#

I have three listboxes in windowsform app. 我在Windowsform应用程序中有三个列表框。 I want to display the countries, states, cities in respective three listboxes. 我想在相应的三个列表框中显示国家,州,城市。 But the states should be displayed according to the country selected and similarly for the cities. 但是,应根据所选国家/地区显示城市,并以类似的方式显示城市。

Now the code may not seem an issue for two three countries, but what if I take a practical situation keeping in mind all countries of the world and their corresponding states and cities. 现在,对于两个三个国家而言,该代码似乎不是问题,但是如果我考虑到现实世界的情况,同时牢记世界上所有国家及其相应州和城市的情况,该怎么办。

What will be the best way to implement this ? 实施此方法的最佳方法是什么?

Update --- I actually wanted to ask what data structures will be best for this ? 更新 ---我实际上想问一下哪种数据结构最适合呢?
A 3d jagged array wiil work fine .nO ? 一个3d锯齿状的数组可以正常工作。 or are there any better ways to do this ? 还是有更好的方法来做到这一点? i have no idea how to do this . 我不知道该怎么做。 Can anyone code this ? 任何人都可以编码吗?

load all the countries into the first list. 将所有国家/地区载入第一个列表。 when the user selects a country clear the state/providence and city list boxes. 当用户选择国家/地区时,请清除州/省和城市列表框。 load the cities for the select state/providence. 为所选州/省加载城市。 when a state/providence is selected load the cities. 选择州/省时,加载城市。

additional options: 附加选项:

  1. have the user enter their postal code (assuming there are international code) and lookup up the city based on the code. 让用户输入邮政编码(假设有国际代码)并根据该代码查找城市。
  2. allow the user to enter this into free form text boxes instead of a predefined list. 允许用户将其输入自由格式文本框,而不是预定义列表。
  3. require the user to enter the first N characters before populating the list with matching choices. 要求用户输入前N个字符,然后再使用匹配的选项填充列表。

Generally a top down hierarchy is applied. 通常,采用自上而下的层次结构。

  1. Bind the countries list (nothing else) 绑定国家列表(仅此而已)
  2. On country selection, bind/rebind the states list filtered for the country & clear the city list. 在选择国家/地区时,绑定/重新绑定为国家/地区过滤的州列表并清除城市列表。
  3. Finally on a state selection, bind/rebind the city dropdown. 最后在状态选择上,绑定/重新绑定城市下拉列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM