DataGridView、数据绑定和 ComboBox 过滤
我有一个 DataGridView,其中有一个组合框列,显示可能的价格,我只想显示与特定行相关的价格。
更详细地说,假设我有一个类方法,它返回一个包含 2 个表的数据集(由在 SQL Server 2005 数据库上运行的存储过程提供)。
第一个表包含订单详细信息行,第二个表包含每种产品的有效价格。
基本上,数据集中的数据表如下所示。
OrderDetails
ProductType | ProductID | Qty | SelectedPrice |
DairyProduct | Milk | 5 | 5.50 |
Fruit | Orange | 7 | 6.90 |
等等...
在数据集中的价格表中,我拥有订单日期内所有产品的有效价格。
Prices
ProductType | ProductID | Price |
DairyProduct | Milk | 5.50 |
DairyProduct | Milk | 6.90 |
DairyProduct | Milk | 7.90 |
Fruits | Orange | 6.90 |
Fruits | Orange | 4.50 |
等等...
我将 OrderDetails 表绑定到 DataGridView,用户需要对其进行修改。
我希望 DataGridView 的价格列显示数据集第二个表中的价格。
我已经成功做到了这一点,现在每一行都有一个组合框,但组合框显示了我的价格表中的所有价格,而我想要的只是它显示对该特定产品有效的价格。 例如,如果用户单击牛奶行上的 DataGridView,则它应该仅显示牛奶的价格,而不是全部价格。
我不知道如何实现这一目标。 有什么指示或例子吗?
预先非常感谢!
我正在 VS 2008 上使用 C# 和 WinForms 进行开发。
I have a DataGridView with a combobox column in it, showing the possible prices, and I would like to only display the prices relevant to the particular row.
In more details, let's say that I have a class method which returns me a dataset with 2 tables populated (feeded by a stored procedure running on a SQL Server 2005 database).
The first table contains the Order Details rows and the second table the prices valid for each of the products.
Basically, my DataTables from the dataset looks like this.
OrderDetails
ProductType | ProductID | Qty | SelectedPrice |
DairyProduct | Milk | 5 | 5.50 |
Fruit | Orange | 7 | 6.90 |
and so on...
On my prices table from the dataset, I have all the prices valid for all products for the order date.
Prices
ProductType | ProductID | Price |
DairyProduct | Milk | 5.50 |
DairyProduct | Milk | 6.90 |
DairyProduct | Milk | 7.90 |
Fruits | Orange | 6.90 |
Fruits | Orange | 4.50 |
and so on...
I'm binding my OrderDetails table to a DataGridView, which the user will need to modify.
I would like the price column of the DataGridView to display the prices from my second table of the dataset.
I've managed to do that, and I now have a combobox for each row, but the ComboBox is displaying all the prices from my prices table, and what I would like to have is only it display the prices valid for that particular product.
For example, if the user clicks the DataGridView on a Milk row, it should only display the prices for the milk and not all of them.
I'm not sure how to achieve that.
Any pointers or examples?
Thanks a lot in advance!
I'm developing on VS 2008, in C# and WinForms.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您需要将组合绑定到对象而不是直接绑定到数据源。该对象是按 ProductID 分组的价格列表
looks like you need to bind combo not to datasource directly but to object. the object is a list of prices grouped by productID