Solved

Filter records on Combo Selection from another Datasource

Posted on 1998-11-16
6
228 Views
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.

0
Comment
Question by:Stefaan
6 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1346994
what is exactly the problem? ps. have you got RXLib?
0
 
LVL 3

Author Comment

by:Stefaan
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.

0
 
LVL 27

Expert Comment

by:kretzschmar
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);
begin
  query2.close;
  query2.ParamByName('SupId').AsFloat := DBLookupComboBox1.KeyValue;
  query2.open;
end;

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.

meikl
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Expert Comment

by:zac
ID: 1346997
Stefaan,

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

Cheers,

Zac
0
 
LVL 3

Author Comment

by:Stefaan
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.
0
 
LVL 1

Accepted Solution

by:
zac earned 100 total points
ID: 1346999
Stefaan

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);
begin
  Accept := (DataSet['MasSupplierID'] = vwSuppliers.FieldByName('MasSupplierID').Value)
end;

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

Cheers,

zac
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

786 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