Link to home
Start Free TrialLog in
Avatar of jfgrayiii
jfgrayiii

asked on

Setting up a button to Control a data grid

I am trying to creat a button that on click event will be to move to records beging with certian letters in the Data Grid

Example

2 Fields

Artist
Title


When you push the Button with the label A it will move the grid to all the A;s in the data grid

The data base is access using ADO connection string





Avatar of kretzschmar
kretzschmar
Flag of Germany image

is your dataset sorted?

yes -> use the locate-method of the dataset
  buttonclickevent
   dataset.locate(fieldname,TButton(sender).Caption,[loPartial]);

no -> use the filterproperty of the dataset
  buttonclickevent
    dataset.filter('fieldname like '+quotedstr(TButton(sender).Caption+'%'));  //replace % with * for accessDB
    dataset.filtered := true;

just from head, means not tested and typos possible

meikl ;-)
Avatar of jfgrayiii
jfgrayiii

ASKER

Is caption where I will put the value I want filtered

example show me only  Filed named Artist that starts with 'A'

here's a quick example i wrote for you

put 2 buttons on the form
set button 1's caption to 'A'
set button 2's caption to 'B'
use the same OnClick event for each button and do this

procedure TForm1.AtoZButtonClick(Sender: TObject);
    var
        s: string;
    begin
        s := (Sender as TButton).Caption;
        Table1.FindNearest([S]);
    end;
hmm, as far as i know findnearest requires an index

>Is caption where I will put the value I want filtered
yes, this caption was meant of the botton, as in TheRealLoki sample

meikl ;-)
ASKER CERTIFIED SOLUTION
Avatar of pcsentinel
pcsentinel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial