Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Filter records on Combo Selection from another Datasource

Posted on 1998-11-16
Medium Priority
Last Modified: 2010-04-04
Hi Folks,

I have a form which refers to a datamodule.  The Datamodule contains 2 TQuery objects (vwSuppliers and vwContacts).  On my form I have a grid which shows all contact records.  What I would like to do, is add a ComboBox to my form in which the user could select a Supplier name and which should then filter the vwContacts query to show only the Contact records for the selected Supplier (link field is MasSupplierID).  

Can anybody tell me how I should handle this ? I thought I've done it before, but I just can't remember how to do it.

Any help or information concerning this would be greately appreciated.

Thanks a lot in advance.

Question by:Stefaan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1346994
what is exactly the problem? ps. have you got RXLib?

Author Comment

ID: 1346995
Well, my problem is that I don't know how to handle this.  Should I use a DBComboBox, a DBLookupComboBox or a simple ComboBox and fill it up myself.  I can't seem to figure out how I should fill the combobox with the values of the suppliername and when the user selects a supplier, I should pass the SupplierID of that Suppleir record to a Filter.  I've tried different things, but can't figure out how to do it.

Any help would be appreciated.

LVL 27

Expert Comment

ID: 1346996
hi stefaan,

it works with a dblookupcombo,

to setup the combo

Listsource = Datasource pointed on your vwSuppliers
ListField = the field you will display
Keyfield = MasSupplierID

by the OnClick-event on this Box

procedure TForm1.DBLookupComboBox1Click(Sender: TObject);
  query2.ParamByName('SupId').AsFloat := DBLookupComboBox1.KeyValue;

This is Now with a Parameter, but you can build a filter also.
Maybe you will check that the keyvalue changed, then you should buffer the KeyValue in a global-var and compare it.

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Expert Comment

ID: 1346997

As long as I understand your question correctly is is relatively simple.

Your vwSuppliers query will be something like:
select * from Suppliers

As kretzschmar said use a dblookupcombo thus:
Listsource = Datasource pointed on your vwSuppliers
ListField = the field you will display
Keyfield = MasSupplierID

with no value for either datasource or datafield.

Your vwContacts query will look like this:
select * from Contacts where MasSupplierID = :MasSupplierID

And then Datasource property of the vwContacts query will be vwSupplier.

this will force a master-detail relationship, and as you slect an item from the list box the the value of the parameter (:MasSupplierID) in the detail query get changed automatically and re-executed.

This is my favorite solution as it involves no coding and happens at the dataset level



Author Comment

ID: 1346998
This all seems to work quite good, but what if I want to include an option, so that the user can select ALL SUPPLIERS.

The solution proposed works fine if the user can only select one Supplier, but I would like the user to have an additional option to select all Suppliers.

Anyway, if nobody comes up with something concerning this matter, I'll use the suggestions made here, and I could divide the points over you 2 (or give you both the points).

Thanks a lot for your input.

Accepted Solution

zac earned 300 total points
ID: 1346999

An alternative would be to use the same set up as I suggested above, but without linking the two datasets and without a where condition on the second query.

You could then use OnFilterRecord to manually filter the records using code something like this:

procedure TForm1.Query1FilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
  Accept := (DataSet['MasSupplierID'] = vwSuppliers.FieldByName('MasSupplierID').Value)

You would have to set the filtered property to true or false depending on some user input such as a check box (filtered?)

I hope this helps



Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question