views:

59

answers:

1

Hello,

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.

+1  A: 

looks like you need to bind combo not to datasource directly but to object. the object is a list of prices grouped by productID

Arseny
Sorry, can you please expand on that? Or maybe with an example? Thanks.
Kharlos Dominguez
I mean bind combo to a List object. this list created as selection of prices where ProductId= currentID.
Arseny
I guess I could do that indeed if it was an external combobox, but here the combobox is inside the dataGridView, is there an event I can react in order to supply the filtered list based on the ID of the current row?
Kharlos Dominguez
I think clicking on a row you can handle that event and get current procuctID bound to this row. anyway it is my suggestion only.
Arseny
I have sorted it out by having two binding sources. One that is filtered with a DataRelation and that I set on the EditingControlShowing, which filters the record for the current row in the ComboBox. I set it back to unfiltered binding source on the CellEndEdit event.
Kharlos Dominguez