• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

DBgrid in delphi

Hello All,
I have a dbgrid connected to a datasource which points at a table.  I am trying to implement an edit field in which as you type the first few letters of a name will move the current table pointer to a record which begins with those letters, while still keeping the entire table in the dbgrid.  The only way I have done this so far is to use sql which only displays the results and not the entire table, can someone help?
Also I wish to sort the information in my DBgrid by a Lastname field, and not the key field, how is this done?

Thanks in advance,
Justin
0
jonzer12
Asked:
jonzer12
1 Solution
 
ILECommented:
Exactly what u wont :))

on form is one  one edit componet and dbgrit,table and data source


procedure TForm1.FormActivate(Sender: TObject);

begin
  Table1.DatabaseName := 'DBDemos';
  Table1.TableName := 'Customer.db';
  Table1.Active := True;
  Table1.IndexName := 'ByCompany';
end;

procedure TForm1.Edit1Change(Sender: TObject);

begin
    Table1.FindNearest([Edit1.Text]);
end;



this is example taken from delphi
0
 
kretzschmarCommented:
? ILE thats just uncomplete

findnearest works only with indexed fields

i would advice to use the locate-method for non-indexed fields, like


procedure TForm1.Edit1Change(Sender: TObject);
begin
  if not Table1.locate('LastName',Edit1.Text,[loCaseInsensitive, loPartialKey]) then
    ShowMessage('No Match');
 
end;

but personally better i think is to use a filter like

procedure TForm1.Edit1Change(Sender: TObject);
begin
  Table1.DisableControls; //no updates to the controls
  try
    Table1.Filtered := False;
    Table1.Filter := 'LastName = '+quotedstr(Edit1.Text+'*');
    Table1.Filtered := True;
  finally
    Table1.EnableControls; //Show result
  end;
end;

meikl ;-)

locate('LastName',Edit1.Text,[loCaseInsensitive, loPartialKey]) then
    ShowMessage('No Match');
 
end;

0
 
kretzschmarCommented:
ignore the last three lines above :-))
0
 
CleanupPingCommented:
jonzer12:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
kacorretiredCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to accept kretzschmar's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup Volunteer
0

Featured Post

Technology Partners: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now