Use combobox to select data to show in datagrid

Rakstip

Member
Joined
Mar 14, 2005
Messages
14
Location
Alsip, IL USA
Programming Experience
Beginner
I am trying to create a small inventory app.

I am using a combobox on my form to select a category title in a database.
I want the datagrid to only show records with that category title. I already have the conn,data adapter and dataset configured to show all records from the database in the datagrid on the form load.
 
Here's what you should do. Retrieve all the IDs and names from your Category table into a DataTable. Bind that DataTable to your ComboBox, setting the name column as the DisplayMember and the ID column as the ValueMember. Retrieve all your inventory records into a DataTable and bind it to your DataGrid. Now you handle the SelectedIndexChanged event of the ComboBox and set the DefaultView.RowFilter property of the inventory DataTable:
VB.NET:
myInventoryTable.DefaultView.RowFilter =  "CategoryID = " & myCategoryCombo.SelectedValue.ToString()
 
Back
Top