如何使用Datagridview项填充Combobox。 [英] How to populate Combobox with Datagridview items.

查看:77
本文介绍了如何使用Datagridview项填充Combobox。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个DataGridView显示来自数据库的项目,我一直在过滤所有这些项目。



我使用查询构建器来制作使用

I currently have a DataGridView that displays items from a database, and I''m stuck on filtering all these items.

I used the query builder to make an SQL statement using

Subject LIKE ? + '%'

Topic LIKE ? + ''%''

通过两个文本框进行过滤。这很好,但我宁愿使用Combobox'。



我要做的是使用Combobox进行过滤而不是文本框。

第一个Combobox需要有一个数据库中所有不同主题的列表,第二个Combobox需要显示当前在datagridview中显示的所有不同主题(所以只有与主题相关的主题)显示当前过滤的主题)



对不起,如果这有点难以理解,我很乐意在需要时跟进更多信息。



提前致谢。

which filters via two textboxes. This works fine, however I''d much rather use Combobox''s.

What I''m trying to do is use a Combobox for filtering instead of a textbox.
The first Combobox needs to have a list of all the different Subjects in the database, and the second Combobox needs to show all the different topics that are currently shown in the datagridview (So only the topics related to the currently filtered subject are shown)

Sorry if this is a little hard to understand, I''d be happy to follow up with any more information if needed.

Thanks in advance.

推荐答案

您可以实施以下解决方案

1.填充主题和主题表

2.将两个表添加到数据集

3.添加主题和主题之间的关系(请参阅以下链接)

4.在一个组合中填充主题

5.在另一个组合中填充主题。现在,当用户选择主题时,主题组合将自动过滤。





以下链接将告诉您如何添加关系

http://msdn.microsoft.com/ en-us / library / ay82azad(v = vs.80).aspx [ ^ ]
You can implement the following solution
1. Populate both Subject and Topics tables
2. Add both tables to a DataSet
3. Add relationship between Subject and Topics (See the below link)
4. Populate Subject in one Combo
5. Populate Topics in another combo. Now when user select a subject, the topics combo will get filtered automatically.


The following link will tell you how to add relationships
http://msdn.microsoft.com/en-us/library/ay82azad(v=vs.80).aspx[^]


这篇关于如何使用Datagridview项填充Combobox。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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