Board index » delphi » Finding fields in DBGrid

Finding fields in DBGrid

I'm using a SQL query to display data in DBGrid, and would like to select
fields based on a partial match.
So I don't know how to select a field without knowing it's full content.
if a field has 'DELPHI' as it's value can I find it by searching for 'DEL'
or 'D' ?

Thanks for your time,

-Danny-

 

Re:Finding fields in DBGrid


I think you will just have to iterate through the fields and "look" at the
field name to see if there is a match.
Quote
Danny wrote:
> I'm using a SQL query to display data in DBGrid, and would like to select
> fields based on a partial match.
> So I don't know how to select a field without knowing it's full content.
> if a field has 'DELPHI' as it's value can I find it by searching for 'DEL'
> or 'D' ?

> Thanks for your time,

> -Danny-

Re:Finding fields in DBGrid


Your message is very confusing.  Are you trying to find a field by the name
of the field or are you trying to find a record in a table using the value
stored in a field?

--
Bill Todd
(Sorry but TeamB cannot answer questions received via email)
(Remove nospam from my email address to contact me for any other reason)

Re:Finding fields in DBGrid


Is this what you want?

SELECT * FROM MyTable
WHERE Field1 LIKE "DEL%"

-----------
Jose Garcia
Sydney, Australia

Quote
Danny wrote:

> I'm using a SQL query to display data in DBGrid, and would like to select
> fields based on a partial match.
> So I don't know how to select a field without knowing it's full content.
> if a field has 'DELPHI' as it's value can I find it by searching for 'DEL'
> or 'D' ?

> Thanks for your time,

> -Danny-

Re:Finding fields in DBGrid


Sorry, I wasn't very clear on the subject, I'm trying to find a record in a
table using the value stored in a field.
I'll try with an example:
You've probably used Norton Commander, to find a file in a directory. You
press ALT and type in the name of the file you're looking for, and as you
press the first key (say 'C', for example), NC moves the selection to a file
named 'CONFIG.SYS'. Then you press 'O' and the selection stays on
'CONFIG.SYS', as it still matches what you're typing. Then you press 'M',
and selection moves to 'COMMAND.COM' . Note that while the selection moves
as you type, you can still see files that don't match your search.
Now, say that a directory is DBGrid and files are a result of SQL SELECT. I
wanted to make the same kind of search for DBGrid. SQL SELECT wouldn't help
as it actually removes entries from DBGrid which do not match the SELECT
query. I was hoping to find something like LOCATE or FINDKEY  for TTable,
but applicable to DBGrid.

Hope I'm not as confusing this time,
thanks for your time,

-Danny-

Re:Finding fields in DBGrid


My advice on this is to not spend the time (and money) coding a tool when one
(or more) already exists.  The decreased development time can add up to lots of
revenue realized earlier.  Unless, of course, this is more of a quest for
knowlege than for a canned solution.
Quote
Danny wrote:
> Sorry, I wasn't very clear on the subject, I'm trying to find a record in a
> table using the value stored in a field.
> I'll try with an example:
> You've probably used Norton Commander, to find a file in a directory. You
> press ALT and type in the name of the file you're looking for, and as you
> press the first key (say 'C', for example), NC moves the selection to a file
> named 'CONFIG.SYS'. Then you press 'O' and the selection stays on
> 'CONFIG.SYS', as it still matches what you're typing. Then you press 'M',
> and selection moves to 'COMMAND.COM' . Note that while the selection moves
> as you type, you can still see files that don't match your search.
> Now, say that a directory is DBGrid and files are a result of SQL SELECT. I
> wanted to make the same kind of search for DBGrid. SQL SELECT wouldn't help
> as it actually removes entries from DBGrid which do not match the SELECT
> query. I was hoping to find something like LOCATE or FINDKEY  for TTable,
> but applicable to DBGrid.

> Hope I'm not as confusing this time,
> thanks for your time,

> -Danny-

Re:Finding fields in DBGrid


Danny, I'm not sure if this is what you want, but you can put the
following code on the OnChange event of a TEdit.

I'm assuming the following:
Datasource1.Dataset = MyQuery
DBGrid1.Datasource = Datasource1

procedure TForm1.Edit1Change(Sender: TObject);
var SearchOpt: TLocateOptions;
begin
  SearchOpt := [loPartialKey];
  MyQuery.Locate('MyField', Edit1.Text, SearchOpt);
end;

This event will be called every time the text in the Edit changes, the
query will try to locate your record, and the grid will reflect the
result.

-----------
Jose Garcia
Sydney, Australia

Quote
Danny wrote:

> Sorry, I wasn't very clear on the subject, I'm trying to find a record in a
> table using the value stored in a field.
> I'll try with an example:
> You've probably used Norton Commander, to find a file in a directory. You
> press ALT and type in the name of the file you're looking for, and as you
> press the first key (say 'C', for example), NC moves the selection to a file
> named 'CONFIG.SYS'. Then you press 'O' and the selection stays on
> 'CONFIG.SYS', as it still matches what you're typing. Then you press 'M',
> and selection moves to 'COMMAND.COM' . Note that while the selection moves
> as you type, you can still see files that don't match your search.
> Now, say that a directory is DBGrid and files are a result of SQL SELECT. I
> wanted to make the same kind of search for DBGrid. SQL SELECT wouldn't help
> as it actually removes entries from DBGrid which do not match the SELECT
> query. I was hoping to find something like LOCATE or FINDKEY  for TTable,
> but applicable to DBGrid.

> Hope I'm not as confusing this time,
> thanks for your time,

> -Danny-

--
-----------
Jose Garcia
Sydney, Australia

Other Threads