combobox and datagrid

minn

Active member
Joined
Apr 10, 2006
Messages
37
Programming Experience
Beginner
Hi,

I have a combo-box called vendor, with items such as microsoft, adobe, macromedia etc etc.

When i select a vendor from the list i want to see records in the software table for only the selected vendor in a datagrid format.

For example, I select Microsoft, then in my datagrid should appear all software details for microsoft software.

Please note that the vendors and software table are linked via the key VendorID which is a primary key in the vendors table and foreign key in the software table.

Please can someone help me get started as i am new to all of this!!!!
 
need a bit more info. Is VendorID literally "Microsoft", "Adobe"

or do you have VendorName=Microsoft, VendorID=1 etc?


i will write this advice as if it is the latter:

So here's it in brief:
Use server explorer to drop vendor and product tables onto a dataset designer, hopefully you also have a table that decodes your ID 1 into "Microsoft" too (the lookup table) - drop that on the designer

draw the relationship between the tables from parent to child

you now have 3 data tables and a relation. you dont need to relate the lookup table

make a new windows form (Form1) and open the data sources window (data menu i think)

in the DS window find the vendor table and click it. the name turns into a combo box, so drop it down and choose details, not grid

expand it and youll see all the column names undernetah. in the same way as you just did, change the VendorID to a combobox

now drop the vendor table on the form

many controls appear, and our vendor id is a combobox

with this control we change the datasource to be the lookup table, the displaymember to be the nice word Microsoft (column name vendorname) and the valuemember to be the VendorID (1)

now we set our combo to filter the Vendors data table when its selected item is changed.. remember that youre filtering by ID, so pull the value out of the SelectedValue property (1) not the SelectedItem property(Microsoft)

now we go to the data sources window again and looking under the Vendors expanded list, we see the products table in dataview mode. note that im talking about this:
+VendorLookup
+Vendors
| (some column names)
+-Products
+Products

yes,m thanks to your relation there will be 2 Products tables.. one is top level on its own, other is a child of vendors. be sure to pick the CHILD one!

drop it on the form. a new grid appears, a binding source appears for it too. if you click this binding source you will see the datamember property is the VENDORS_PROCUCTS relation, not the prodicts datatable. this makes VS filter the results to jsut produtcts fromthat vendor

one last thing, in your form load, ensure that your products datatable is being filled

if you have millions of procducts it would be a good idea to change the way you fill the table. see my latest question in the forum for this (how to show data from multiple tables)

but now you should have a combo that when you change it, it causes a filter operation on the vendors table, which causes the relation to filter the products to show only those in the grid from that vendor
 
i am using the latter, where vendors translates to a vendor id in another table and unfortunately for you, i am using vs2003

Thanks
 
Back
Top