Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-26
6
Medium Priority
?
459 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
[X]
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
6 Comments
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 390 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 210 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 150 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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