Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Filtering data in one combobox column of grid depending on the value of another comboboxcolumn of the grid
 

Filtering data in one combobox column of grid depending on the value of another comboboxcolumn of the grid

Filtering data in one combobox column of grid depending on the value of another comboboxcolumn of the grid
tariqmoh  Wednesday, July 15, 2009 8:43 AM
Hi Tariqmoh,

Let's say there're two columns in the DataGridView, called column1 and column2. The column2 is a DataGridViewComboBoxColumn.

To filter data in the column2, handle the EditingControlShowing event of the DataGridView. If it's the column2, get the current editing control, convert its type to ComboBox and then set the DataSource property of the hosted combobox according to the value under the column1 of the same row.

Thus, you implement the "filtering" function for the column2.

Hope this helps.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. end us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
Linda Liu  Monday, July 20, 2009 9:13 AM

Add event selectedindex change event to combobox by using following code

Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing

        Dim editingComboBox As ComboBox = e.Control
        AddHandler editingComboBox.SelectedIndexChanged, AddressOf Me.editingComboBox_SelectedIndexChanged

End Sub
Private Sub editingComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

End Sub
then in that event reassign the datasource to first ComboboxColumn.
NareshG  Wednesday, July 15, 2009 11:58 AM
Hi Tariqmoh,

Let's say there're two columns in the DataGridView, called column1 and column2. The column2 is a DataGridViewComboBoxColumn.

To filter data in the column2, handle the EditingControlShowing event of the DataGridView. If it's the column2, get the current editing control, convert its type to ComboBox and then set the DataSource property of the hosted combobox according to the value under the column1 of the same row.

Thus, you implement the "filtering" function for the column2.

Hope this helps.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. end us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
Linda Liu  Monday, July 20, 2009 9:13 AM

You can use google to search for other answers

Custom Search

More Threads

• binding combobox to object
• Add results of form into a MSQL DB
• how to save changes made to data bound to datagridview
• CHECKBOX Validation Problem : DATAGRIDVIEW
• is it possible to scan barcode data to datagird cell ?
• alert a user "To Save changes or ignore changes" when editing records in VB 2005
• Copy & Paste functions in datagrid?
• what is standard way for Save/Retrive Color type into/from windows registry?
• How to display specified no.of rows in a datagridview in windows application
• Accessing data through internet