在datagridview中级联组合框 [英] Cascading comboboxes in datagridview

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

问题描述

大家好,

我需要一个简单的项目,如何将3个组合框(例如地区,国家和城市)与其反映的交易表级联,为datagridview绑定数据源,我建了很多次但是当需要选择一些
行时有bug,我希望能够通过datagridview直接添加数据...请帮助附加材料。

Please i need a simple project to how to cascading 3 comboboxes of (for example Region ,Country and city) with their reflected transaction table which is the Binding datasource for datagridview ,i built it many times but with bugs when need to select some row ,i want to be able to add data via datagridview directly ... please help with attached material.

谢谢

Esmat

推荐答案

如果没有看到您的代码,就无法指导您找到解决方案。

Without seeing your code it's impossible to direct you to a solution.

我可以根据
代码示例
我为MSDN做了。首先,代码示例执行级联ComboBox或ListBox,而不是DataGridView,但底层逻辑没有区别,因为您将在DataSet中设置三个DataTable,设置三个表之间的关系,将
的DataSet表分配给三个BindingSource组件,设置DataMember和关系名称。因此,当在第一个DataGridViewComboBoxColumn中进行选择时,第二个和第三个将仅基于第一个进行有效选择。因此,如果他们在第一个DataGridViewComboBox中选择
第一项,则第二项仅显示特定于第一个DataGridViewComboBox的相关值,第三项仅显示基于第二个DataGridViewComboBox的选择。

I can give you an idea based off a code sample I did for MSDN. First off, the code sample does cascading ComboBox or ListBox, not a DataGridView but the underlying logic is no different in that you would setup three DataTables in a DataSet, set the relations between the three tables, assign the DataSet tables to three BindingSource components, set the DataMember and relationship names. So when a selection is made in the first DataGridViewComboBoxColumn the second and third will have only valid selections based on the first. So if they pick the first item in the first DataGridViewComboBox the second would only show related values specific to the first DataGridViewComboBox and the third would only show selections based on the second DataGridViewComboBox.

注意,必须针对与DataGridView的基础DataSource中的字段匹配的DataMember设置第一个DataGridViewComboBoxColumn。

Note the first DataGridViewComboBoxColumn must be setup in regards to the DataMember that matches a field in you underlying DataSource of the DataGridView.

如果没有为DataGridView使用DataSource,这将使得安排更多很难,您必须绑定到DataGridView的一个或多个事件,并手动设置当前行的下一个DataGridViewComboBox列的值。使用带有我上面提到的逻辑的DataSource时,
会变得混乱而且不易维护,它很容易维护并且表单中的代码更少。

If not using a DataSource for the DataGridView this makes the arrangement much more difficult in that you must tie into one or more events of the DataGridView and manually setup values for the next DataGridViewComboBox column for the current row. It will get messy and not easy to maintain while using a DataSource with the logic I mentioned above it's easy to maintain and less code in your form.

最后,如果使用的话DataSource,其中数据从TableAdapter / DataSet和BindingSource引入,它们可能以不同的方式混乱,然后根本没有数据源。我不是TableAdapter / DataSet和BindingSource的粉丝,除了超级简单数据
操作,其中级联DataGridViewComboBox不是。

Lastly, if using a DataSource where the data is brought in from a TableAdapter/DataSet and BindingSource that can be messy in a different way then no data source at all. I'm not a fan of TableAdapter/DataSet and BindingSource other than super simple data operations where cascading DataGridViewComboBox is not.


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

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