#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    169
    Rep Power
    37

    Auto scrolling on db grid


    I have a dbgrid that reads all the customer sales. I have 3 sales people. In stead of clicking one by one and see what sales they made i want to put the screen on a projector and select each one individually (and automatically) and display their sales. Then i like the grid to scroll automatically as well. A MOUTH FULL i know.

    So what i did is but a timer on with a 20 seconds delay. Read my sales people table. But now how do i tell the LOOP that it must stay there for 20 seconds display the info on the dbgrid.the dbgrid must start scrolling so that all the sales can be viewed for that sales person. Is this possible?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    356
    Rep Power
    7
    Add another Timer to your application, play with the interval to what you want, and add the following code to your timer's OnTimer event.
    Code:
    TForm1.Timer1Timer(Sender: TObject);
    begin
       DBGrid1.Perform(WM_KEYDOWN, VK_DOWN, 0);
    end;
    This code will continue to run even after it has scrolled to the end of the list. You should probably look to add code to ensure you haven't reached Datasource's EOF.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    169
    Rep Power
    37

    Re


    thx majlumbo. Works like a charm. I see what you mean with the end of records story. Lets say i refresh my screne every 20 seconds and i have 50 records in the table. So what that means i get to record 20 the screen refresh and the loop through each record starts at 1.Whats the best wayto approuch this. Run a Count of the amount of records before hand and use a count that increment on the timer? thx for your help so far.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    356
    Rep Power
    7
    I was thinking about this after I posted my reply. I believe that the code I posted not only scrolls the DBGrid, but it also advances to the next record. So all you need to do is set the timer's Enable property to false when your dataset reaches is EOF.

    So I would just modify the OnTimer Event like so
    Code:
    TForm1.Timer1Timer(Sender: TObject);
    begin
       DBGrid1.Perform(WM_KEYDOWN, VK_DOWN, 0);
       Timer1.Enabled := Not Query.EOF;//or Table.EOF depending on component used
    end;
    This turns off the timer when your query/table reaches the last record and tries to advance one more and can't.

    If it turns out that it doesn't actually advance to the next record, then you may need to "hack" the DBGrid, to see if it has reached the end.

IMN logo majestic logo threadwatch logo seochat tools logo