Solved

How to return Selected Row information from DBGrid back to calling form when DBGrid filtered with SQL?

Posted on 2004-09-26
6
430 Views
Last Modified: 2010-04-05
Hi All,

I have a search form which allows a "Select *" type SQL statement to be performed on a table when first opened.

The intent is for the user to be able to filter the SQL statement further, and then to return the selected item back to the calling form, in order to be able to update that form, or alternatively to review details (based upon the selected item).

So far so good - I have the filter and the search form going well

The problem that I have is when I want to select that record and review it in the calling form, or use the information to update the calling form.

I've tried using RecNo, but that will only give me the correct record associated with the unfiltered search.

If I filter the search, RecNo could well be for example, the ninth record overall, but only the second record when filtered. The result returned to the form is the second record overall.

How can I get this item to perform for me, so that as per the example: the second filtered record on the DBGrid is returned as the correct ninth record overall to the calling form?

thanks in Advance
0
Comment
Question by:gunnadothat
6 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 130 total points
ID: 12155573
use simply a Locate....

I mean to apply a locate to the overall with the fields values from the search

For example your overall structure is

Id   Name   Age

1    Alan     10
2   Jhon      12
3   Mark      13

and the search result is 2 jhon 12

you can pass a Overall.Locate('ID;NAME;AGE',
                                             VarArrayOf([search.fieldbybyname('id').AsInteger,
                                             search.fieldbybyname('Name').AsSTring,
                                             search.fieldbybyname('AGe').AsInteger]),[]);

This will locate 2^ record on Overall
0
 
LVL 17

Assisted Solution

by:geobul
geobul earned 70 total points
ID: 12158200
Hi,

It seems that you are having two query objects - one on the main form and one on the search form. And you want to pass a selected record number (some info) to the main form in order to main form's query to go to that record.

If that is correct then perhaps you could use one query object on the main form only, use the same query in the select form and after 'filtering', selecting a record and closing the select form your main form's query will be positioned on the right record automatically (the query will remain filtered, of course, but that shouldn't be a problem because your users can always open the search form again and remove all current filters).

Regards, Geo
0
 
LVL 11

Assisted Solution

by:calinutz
calinutz earned 50 total points
ID: 12159835
On the OnKeyUp event of the Searching form place this code:

begin
If ((key=13) and (ssCTRL in Shift)) then
begin
InitialForm.Edit1.Text:=DBGrid1.Fields[0].AsString;
InitialForm.Edit2.Text:=DBGrid1.Fields[1].AsString;

Close;
end;
If key=27 then Close;
end;

// this code returns from the search form closing it and if you press CTRL+Enter on a record then It sends the value from the chosen record to the Initial Form.

// I hope this is what you needed
0
 
LVL 17

Expert Comment

by:geobul
ID: 13343285
My recommendation : split the points.
0
 

Author Comment

by:gunnadothat
ID: 13351715
Hi All,

sorry about not finalising this earlier - Uni had finished for the year and I simply forgot to complete the feedback.
Please accept my apologies.

I've split the points according to the use that I made of the answers - all were good, but I used Ferruccio68's answer as the basis for the filter, and the other responses were great to put it all into perspective.

Once again, i apologise for not doing this sooner, and thanks Dan for the prompt to complete this item - much appreciated to all.

regards

GdoT
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

829 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