使用数据绑定的ComboBox和DataGridView [英] Work with a data bound ComboBox and DataGridView

查看:86
本文介绍了使用数据绑定的ComboBox和DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个桌子.一个包含两列,其中一列与ComboBox绑定.另外两个表与两个单独的DataGridView绑定,但是与第一个表相关,因此它们都有一个辅助键,该辅助键与第一个表的ID列(第一列)匹配(以便DataGridViews中显示的行具有相同的辅助键)键值作为当前选中的第一行的ID).这可以通过将Visual Studio本身生成的菜单与其他组件一起使用来实现,但我希望在ComboBox中使用此功能,以便当我从中选择一个项目时,应在DataGridViews中显示相应的行.我该怎么办?
预先感谢.

I have three tables. One has two columns of which one column is bound with a ComboBox. Other two tables are bound with two separate DataGridViews but are related to the first table so that they both have a secondary key which matches up with the ID column(first column) of the first table(so that rows displayed in DataGridViews have the same secondary key value as the ID of the first table row currently selected). This works by using the menu generated by Visual Studio itself with the other components but I want this functionality in the ComboBox so that when I select an item from it, the corresponding rows should be displayed in the DataGridViews. How do I do it?
Thanks in advance.

推荐答案

处理组合框的onchange事件(这些事件在属性窗口的选项卡上列出)
从组合框中获取选定的项目
将过滤器应用于填充DGV的集合.
Handle the onchange event of the combobox (events are listed on the tab in the properties window)
Get the selected item from the combobox
Apply a filter to the collection populating the DGVs.


处理ComboBox的onChange事件,并获取Combo Box的选定ID和值.现在将此ID传递给您的函数,以过滤记录,最后将组合框与ur函数绑定.
Handle the onChange event of ComboBox and get the selected id and value of Combo Box. Now pass this id to your function for filtering the record at last bind the combo box with ur function.


这篇关于使用数据绑定的ComboBox和DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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