Filter DGV by combobox programmatically

Ultrawhack

Well-known member
Joined
Jul 5, 2006
Messages
164
Location
Canada
Programming Experience
3-5
I am trying to filter a databound DGV from a combobox. All procedures are strictly read-only.

Access db. 2 tables Countries, Addresses.

Added datasource MyDb
on Data Designer added underlying Select Query to Addresses TableAdaptor
SELECT city + ', ' + State + ' ' + cstr(Zip) + chr(13) + chr(10) + Memo AS Log FROM Addresses

4 fields data is concatenated into single DGV column called Log

Datagridview's datasource = MyDbBindingsource

When form opens datagridview DGV fills perfectly.

combobox cboCountry is databound to Countries table.

When I select a country from cboCountry, DGV should simply filter and show selected country's data.

Filtering the bindingsource does not work as it does not seem to accept standard SQL

So I'm left with having to make changes to the TableAdaptor's underlying SQL.

Can someone please help me with this or suggest a better method ?

Thanks.


 
Last edited:
The bindigsource can only filter on a row or expression related to the datatable. Your SQL never selects the country so you cannot expect the bindingsource to be able to filter on it. Either select the country into another datacolumn, and use a filter of "[Country] = 'whatever'" or define a countries table and establish a relation between the two, bind the combo to the vountries table, and make the log a child of the country. Upon selecting a country, the relation will filter rows not belongign to the relation.
 
Back
Top