Changing DatSource of a combo box column of DataGridView dynamically

afh

Member
Joined
Jul 10, 2017
Messages
15
Programming Experience
5-10
I've a DataGridView based on PROD_PACKING table. The type of PARENT_PACK_ID column is changed to Combo Box. To populate its values I defined a custom query getPackings(product_id) inside the prod_packingTableAdapter that returns PACK_ID, PACK_TYPE based on PRODUCT_ID parameter.

VB.NET:
PACK_ID                       primary key auto increment value
PACK_TYPE                   for packing type e.g. Carton, Box, Unit
PARENT_PACK_ID          self join to PACK_ID
CONV_UNITS                 # of units within parent pack
PRODUCT_ID                 refers to PRODUCT table

How I may change DataSource of the PARENT_PACK_ID combobox column of DataGridView.
 
Last edited:
You have asked how to change the DataSource of the column. The answer is obvious. You assign the new list to the DataSource property of the column. I suspect that the question you asked is not actually the question you want answered though. Do you actually want to know how to use a different data source for each cell within the column?
 
I've created custom table adapter based on following parameterized query. It should get a product_id as parameter to get all of its packaging details. The PROD_PACKING table has a self-join on PARENT_PACK_ID to PACK_ID. The problem is how may I provide the parameter.

SELECT a.pack_id, b.title AS product, c.title AS pack_type
FROM ((prod_packing a INNER JOIN
product b ON a.product_id = b.product_id) INNER JOIN
packing_type c ON a.type_id = c.type_id)
WHERE a.product_id = ?

data source.jpgform.jpg
 
Perhaps you'll answer my question the second time around.
Do you actually want to know how to use a different data source for each cell within the column?
Are you saying, without actually saying, that you want to provide a different parameter value for each row, and thus have a different drop-down list for each row in the grid?
 
I know that that's not straightforward as I've tried before and failed. The column itself has a DataSource property and its value is passed on to the DataSource property of each cell in that column by default, and then the cell's DataSource value is passed on to the DataSource property of any DataGridViewComboBoxEditingControl that gets created and embedded in that cell. In theory, you should simply be able to handle the EditingControlShowing event and assign your list (DataTable or whatever) to the DataSource property of the cell there but, as I recall, there were some unexpected exceptions when I tried that. I'll have another go when I get the chance and get back to you.
 
Back
Top