Filter Datagridview Combobox

sheldon

New member
Joined
Jun 25, 2012
Messages
1
Programming Experience
Beginner
Hi All,

I've been scratching my head over this for a while now and was hoping you might be able to help.

I have a datagrid view, which has a combobox. The combo box is connected to a datasource, i would like to filter the combobox values based upon a date that is selected on that row of the datagrid.

Should i be looking at the datagrid view click event?

Any ideas welcome!


Thanks,

Dan
 
A DataGridView contains no controls by default. When you start editing a cell, a new control of the appropriate type is create and embedded in that cell, or an existing control used if the previously edited cell was the same type. That control will have various of its properties populated from the corresponding properties of the cell, which in turn gets some of its property values from the column. In the case of a DataGridViewComboBoxColumn, it sets the DisplayMember, ValueMember and DataSource of each cell from its own properties of the same name. When an editing control is embedded in a cell, its properties of the same name are set from the cell and its SelectedValue is set from the cell's Value property.

In your case, what you need to do is get notified when an editing control is being embedded in a cell so that you can manipulate it yourself. To do that, handle the EditingControlShowing event of the grid. That will give you access to the editing control and the cell that its being embedded in. If you know the cell then you know the row, so you can get other cell values from the same row to decide how to filter.

If you need to attach any event handlers to the editing control, which it doesn't sound like you do, then you use the AddHandler statement. In that case, make sure that you handle the CellEndEdit event and use the corresponding RemoveHandler statement.
 
Back
Top