我是国家,州和城市的3个组合框.当我选择一个将在第二个组合框中显示核心州的国家时,当我选择一个将在第二个组合框中显示州的城市时... [英] i'he 3 combobox for country,state and cities.when i select one country that coressponing states will display in 2nd combobox,and when i select one state that coressponing cities will display in...

查看:99
本文介绍了我是国家,州和城市的3个组合框.当我选择一个将在第二个组合框中显示核心州的国家时,当我选择一个将在第二个组合框中显示州的城市时...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为国家,州和城市设置了3个组合框.当我选择一个核心国家将在第二个组合框中显示的国家时,当我选择一个核心城市将在第三个组合框中显示的国家时,请给我c#代码.without数据库不使用Windows application

i''he 3 combobox for country,state and cities.when i select one country that coressponing states will display in 2nd combobox,and when i select one state that coressponing cities will display in 3rd combobox .give me the c# code .without database using windows application

推荐答案

解决方案1中给出的链接很好,但它适用于具有JavaScript的HTML.
对于C#,以下过程可用于Windows窗体
使用DataSet 设计器或以编程方式在Country, State and City DataTables之间创建DataRelation.

关系:CountryState
父表:国家/地区和主键:CountryID
子表:状态和外键:CountryID
关系:StateCity
父表:状态和主键:StateID
子表:城市和外键:StateID
The link given in solution 1 is good but it is for HTML with JavaScript.
For C# the following procedure can be used for Windows Forms
Create DataRelations between the Country, State and City DataTables using either the DataSet designer or programmatically.

Relation : CountryState
Parent Table: Country and primary key: CountryID
Child Table: State and Foreign key: CountryID
Relation : StateCity
Parent Table: State and primary key: StateID
Child Table: City and Foreign key: StateID
//Create a BindingSource for Country ComboBox using Country table from DataSet1
BindingSource CountryBindingSource = New BindingSource(DataSet1, "Country");
//Now create a BindingSource with CountryBindingSource as the parent using the relation 
BindingSource StateBindingSource = New BindingSource(CountryBindingSource, "CountryState");
//Then create a BindingSource with StateBindingSource as the parent using the relation 
BindingSource CityBindingSource = New BindingSource(StateBindingSource, "StateCity");

//Set the DataSource, DisplayMember and ValueMember properties of the ComboBoxes as below
comboBox1.DataSource = CountryBindingSource;
comboBox1.DisplayMember = "Country";
comboBox1.ValueMember = "CountryID";
comboBox2.DataSource = StateBindingSource;
comboBox2.DisplayMember = "State";
comboBox2.ValueMember = "StateID";
comboBox3.DataSource = CityBindingSource;
comboBox3.DisplayMember = "City";
comboBox3.ValueMember = "CityID";


检查此
http://www.sitepoint.com/forums/showthread.php? 350291-Country-State-State-City-Dropdown-list [ ^ ]

谢谢
Check This
http://www.sitepoint.com/forums/showthread.php?350291-Country-State-City-Dropdown-list[^]

Thanks


这篇关于我是国家,州和城市的3个组合框.当我选择一个将在第二个组合框中显示核心州的国家时,当我选择一个将在第二个组合框中显示州的城市时...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆