Click here to Skip to main content
15,175,525 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have editable DataGridView to fill ordered Products, so i have a DataGridViewComboBoxColumn with DataTable datasource that contain all products codes, i change the rowFilter of the dataview depending on values of the column. for exmple:

datagridview is empty
Combo product codes are :
11
1212
1555

the user added row and choosed from the combobox code "1212" .
when the user added anther row i filter the combo dataView to exclude the code "1212" so the combo will have :
Combo product codes are :
11
1555

I do this filtering In EditingControlShowing event of the datagridview.

My problem is that the dataGridView uses the same comboBox Instace for the whole column so after i filter its source the cell text of the first row change to empty string cause the combo in the second row doesn't have the value that was choosen in the first row.

Is there any work around?

Thanks a lot!
Posted
Updated 12-Mar-14 18:46pm
v2
Comments
george4986 13-Mar-14 0:46am
   
why dont u use an auto text instead of combo box?

1 solution

In Dropdown selection index changed event, remove the selected item from the dropdown.
It would be something like this,

GridViewRow grdrow = ((DropDownList)sender).Parent.Parent as GridViewRow;
               DropDownList ddlProducts = (DropDownList)grd.Rows[grdrow.RowIndex].FindControl("YourDrpDown");
               ddlProducts.Items.Remove(ddlProducts.SelectedItem);
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900