VB.NET Filtering out datagrid data with combo box
-
Hi there. I currently have an application where a user can select items from a combo box and then display the results in a datagrid view depending on what is selected in the combo box. This is fine because the user is selcting an exact match from what is in the sql connection but i need the user to be able to select a range from a different combo box, ie - if a field/row in the datagrid is 'Total' then i would want the user to be able to filter out all totals between '100 and 200' or '201 - 300' etc. I have tried using a case statement but am unsure if this is the right way of going about it.
-
Hi there. I currently have an application where a user can select items from a combo box and then display the results in a datagrid view depending on what is selected in the combo box. This is fine because the user is selcting an exact match from what is in the sql connection but i need the user to be able to select a range from a different combo box, ie - if a field/row in the datagrid is 'Total' then i would want the user to be able to filter out all totals between '100 and 200' or '201 - 300' etc. I have tried using a case statement but am unsure if this is the right way of going about it.
Not sure how you have your data setup in the app. If you have a data table, use a dataview to filter the data as needed. The dataview.RowFilter is the where clause in a select statement. So, just like you would do in SQL, your filter would be something like "Totals >= 100 and Totals <= 200" or "Totals BETWEEN 100 and 200" I took the example below from the MSDN help which is very descriptive on the dataview.
Private Sub MakeDataView()
Dim view As DataView = New DataView
With view
.Table = DataSet1.Tables("Suppliers")
.AllowDelete = True
.AllowEdit = True
.AllowNew = True
.RowFilter = "City = 'Berlin'"
.RowStateFilter = DataViewRowState.ModifiedCurrent
.Sort = "CompanyName DESC"
End With' Simple-bind to a TextBox control Text1.DataBindings.Add("Text", view, "CompanyName")
End Sub
Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison
-
Hi there. I currently have an application where a user can select items from a combo box and then display the results in a datagrid view depending on what is selected in the combo box. This is fine because the user is selcting an exact match from what is in the sql connection but i need the user to be able to select a range from a different combo box, ie - if a field/row in the datagrid is 'Total' then i would want the user to be able to filter out all totals between '100 and 200' or '201 - 300' etc. I have tried using a case statement but am unsure if this is the right way of going about it.