重置从数据库读取的ComboBox [英] Reset ComboBox that reads from a db

查看:85
本文介绍了重置从数据库读取的ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在窗体上有两个组合框(类别和活动),它们可以从db中读取数据并在其DropDown中显示它们.在类别下,当我选择美容师时,活动ComboBox会自动用理发师,美发师和修指甲填充自身,但是当我在类别ComboBox中重选建筑时,木匠和水管工被添加到理发师,美发师和修指甲中,这是针对美容师的.

选择新类别后,如何重置活动ComboBox DropDown

我试过了,但是没用.

I have two combo box on my form (category and activity) that reads data from the db and display them in their DropDown. under category when I select Beauticians the activity ComboBox automatically fills it self with barber, hair dresser, and manicure but when I reselect construction in the category ComboBox massion, carpentry and plumber get added to the barber, hair dresser, and manicure which is for Beautician.

how do reset the activity ComboBox DropDown when a new category is selected

I tried this but did not work.

this.cboType.Refresh();
this.cboType.Reset();

推荐答案

hi
编写以下代码以清除组合框中的数据
hi
write the folowing code to clear the data in combobox
comboBox1.Items.Clear();


这里combobox1是combobox的对象.

希望这可以解决您的问题.
谢谢.


here combobox1 is an object of combobox.

hope this may resolve your problem.
thanks.


听起来,您是在更改第一个组合框之后手动更新了第二个组合框,而不是直接将其绑定到数据库.如果是这种情况,请在添加新项目之前将DataSource设置为none.这将清空您现有的数据.

这是一个堆栈溢出问题,其中包含有关如何执行此操作的更多详细信息:
http://stackoverflow.com/questions/512385/combobox-refresh-after-从子窗体添加数据 [ ^ ]
It sounds like you are updating your second combo box manually after the first one is changed instead of having it bound directly to the database. If this is the case, set the DataSource to nothing before you add your new items. This should blank out your existing data.

Here is a Stack Overflow question that has more details on how to do this:
http://stackoverflow.com/questions/512385/combobox-refresh-after-adding-data-from-childform[^]


清除第二个组合框的旧内容

clear the older contents of your 2nd combo box

cb2.items.clear();



然后根据它加载新项目.



then load new items in it based on it.


这篇关于重置从数据库读取的ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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