Setting up a button to Control a data grid

Posted on 2005-04-11
Last Modified: 2010-04-05
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


2 Fields


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

Question by:jfgrayiii
    LVL 27

    Expert Comment

    is your dataset sorted?

    yes -> use the locate-method of the dataset

    no -> use the filterproperty of the dataset
        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 ;-)

    Author Comment

    Is caption where I will put the value I want filtered

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

    LVL 17

    Expert Comment

    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);
            s: string;
            s := (Sender as TButton).Caption;
    LVL 27

    Expert Comment

    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 ;-)
    LVL 11

    Accepted Solution

    You can do it without a button.

    Add a TEdit Control called Edit1 to the form.

    On the OnChange event of the TEdit put

    Dataset.Locate('Artist',Edit1.Text,[loCaseInsensitive, loPartialKey]);


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now