链接两个组合框 [英] Linking two combo boxes

查看:84
本文介绍了链接两个组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我有两个Windows形式的组合框,一个用于省份,第二个用于区域.我需要的是,当某人选择一个项目(省)时,所有相关的项目(区)都应出现在第二个组合框中,我已经在DBMS中使用表格完成了此操作,但是我想直接使用c#进行操作,有什么主意吗?请帮帮我!

Dear All,
I''ve two combo boxes in windows form, One is for Province and the second one is for district. All i need is when someone selects an item (Province)all relevant Items (Districts) should come in second combobox, I''ve done it using table in DBMS but i want to do it directly with c#, any idea? Please help me!

推荐答案

您不知道我们的用户界面对您有什么帮助.

关于第一个组合的selecteditemchange事件
获取选定的对象和过滤第二个组合所需的外键
使用第一个组合的FK详细信息过滤第二个组合的数据收集.
As you have given us no clue what your UI is this may help.

On the selecteditemchange event of the first combo
Get the selected object and the foreign key needed to filter the second combo
Filter the data collection of the second combo using the FK details from the first combo.


有两种方法可以执行此操作.第一种方法是具有所有省份的完整列表,以及具有所有地区的另一个列表.用户选择省份时,可以在List<district>上使用LinQ,例如:-
There is 2 ways to do this. The first way is to have a complete list of all provinces and another list with all districts. The when your user selects a province, you can use LinQ on the List<district>, something like :-
var selectedDistricts = from district in Districts where district.ProvinceID == selectedProvince.ID select district;



另一种选择是具有一个在数据库中查找并返回具有所选省份ID的所有地区的函数.即
"



The other option is to have a function which looks up in the database and returns all districts with the selected provinces id.i.e

"SELECT id, name, provinceID, etc FROM Districts WHERE provinceID = @provinceID;" 

,其中provincenid是选定的省份ID.

where provinceid is the selected provinces id.


这篇关于链接两个组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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