Datagridview and ComboBox

ashash

New member
Joined
Oct 5, 2009
Messages
3
Programming Experience
1-3
Datagridview and ComboBox

Hi

I have a datagridview with a column set as a combobox (Product), which is attached to a datasource.

The user should only be allowed to select a product from the combobox once, so ideally I would like the combobox to remove already selected products in previous rows. Is this possible?

i.e. for row 1 the combobox has items "001", "002" and "003".
Then user selects "001" for row 1.

When the user then selects row 2, the combobox should only have items "002" and "003".

I've spend days looking for an similar example on online.... but haven't found nothing.. is it not possible?

Thanks in advance!
 
Do you mean a constraint on the table in the database that populates the combobox? I already have that. But that would allow the user to enter the product again, try and insert it, and then error. I dont want the user to be able to do it in the first place?

Thanks for the quick response by the way!
 
You'd need to populate the drop-down list dynamically. Handle the EditingControlShowing event of grid and check whether your in the right column. If you are, get a reference to the ComboBox control from the e.Control property and populate it directly. You'll have to determine what row your in and then loop through all rows to see what items to include and which to exclude.
 
ive written the bit that exclude items that have already been used, and i understand that I would be that in the EditingControlShowing...

what i dont know how to do is, say that it is the datasource for that cell only... and what do i do when I form is opened, so that it shows the product that has been selected...

Currently i have a datatable that now excludes all previous selected products....
 

Latest posts

Back
Top