Hi!
I have a little problem:
I have a DataGridView and I just filled it with data from source:
this.usedfunc_TableAdapter.Fill(this.mSDOCSDataSet._usedfunc_);
and I created a ComboBox with databound, and it show the first column from the DataGridRow.
I just like to reach when I'm selecting something from the ComboBox, the DataGridView just show that 1 row.
Sry for the annoying question, but im new in programming!
DataGridView filter with ComboBox
Started by vlahob, Jul 04 2010 10:46 PM
1 reply to this topic
#1
Posted 04 July 2010 - 10:46 PM
|
|
|
#2
Posted 13 July 2010 - 06:38 AM
The solution I'll propose requires that DataGridView is not intended to be used to add new rows to the table. If so, the solution is like this:
1. Create DataView object and set its DataSource property to DataTable you used as data source for the DataGridView.
2. Set DataView's RowFilter to empty string (i.e. show all rows).
3. Set DataGridView's DataSource property to DataView object
4. Whenever Combo box selected item changes, set DataView's RowFilter to "IdField=value", where IdField is the field by which you filter and value is the selected value (don't forget single quotes for character fields).
That will make all other rows disappear from the grid and just this one remain.
This is general technique and you can use it to filter by any criteria (e.g. by price range if you have column showing prices, etc.).
1. Create DataView object and set its DataSource property to DataTable you used as data source for the DataGridView.
2. Set DataView's RowFilter to empty string (i.e. show all rows).
3. Set DataGridView's DataSource property to DataView object
4. Whenever Combo box selected item changes, set DataView's RowFilter to "IdField=value", where IdField is the field by which you filter and value is the selected value (don't forget single quotes for character fields).
That will make all other rows disappear from the grid and just this one remain.
This is general technique and you can use it to filter by any criteria (e.g. by price range if you have column showing prices, etc.).
Edited by zoranh, 13 July 2010 - 06:38 AM.
Corrected typo


Sign In
Create Account

Back to top









