Solved

how to use next and prev page in dbgrid?

Posted on 1998-07-01
13
465 Views
Last Modified: 2010-04-04
I want to make a touch-screen program.
I want to use a next and prev button to control dbgrid,
when I click next button,dbgrid will display next 10 record,
when I click prev button,dbgrid will display prev 10 record.
and I don't want the vertical scroll bar displayed in dbgrid.
Can you tell me how to do that?
0
Comment
Question by:nhdcb2
  • 8
  • 4
13 Comments
 

Author Comment

by:nhdcb2
ID: 1356752
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1356753
To move 10 records forward, use :

DM1.Table1.MoveBy(+10);

To move 10 records backward, use :

DM1.Table1.MoveBy(-10);

Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1356754
Hiding vertical scroll bar :

 Try this API : ShowScrollBar(DBGrid1.Handle, sb_Vert, False)

or try this :

In order to remove the vertical scrollbar from a TDBGrid component,
you must override its Paint method.  Inside the Paint method you
must call the SetScrollRange API procedure to set the min and max
scroll values to zero (this disables the scrollbar), and then call
the inherited Paint.  The code below is a unit containing a new
component called TNoVertScrollDBGrid that does this.  You can copy
the code into a file called NEWGRID.PAS, and add it to the component
library as a custom component.


unit Newgrid;

interface

uses
  WinTypes, WinProcs, Classes, DBGrids;

type
  TNoVertScrollDBGrid = class(TDBGrid)
  protected
    procedure Paint; override;
  end;

procedure Register;

implementation

procedure TNoVertScrollDBGrid.Paint;
begin
  SetScrollRange(Self.Handle, SB_VERT, 0, 0, False);
  inherited Paint;
end;

procedure Register;
begin
  RegisterComponents('Data Controls', [TNoVertScrollDBGrid]);
end;

end.

        TI (Borland support pages)

Regards, Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1356755
heck maybe this API might work too :

In a component descending from TDBGrid do something like :
                                   SetScrollRange(Handle, SB_VERT, 0, 0, False);
                             to hide the vertical scrollbar ;
                                   SetScrollRange(Handle, SB_VERT, 0, 4, False);
                             to show it.

Regards, Zif.
0
 

Author Comment

by:nhdcb2
ID: 1356756
Thank you for your help!
I know how to disappear the vertical scroll bar,
but I don't know how to get the last record that is displayed
in the dbgrid.
so I can't make my next and prev button,
I hope you can help me again!
Thanks a lot!
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1356757
? nhdcb2, can you explain this problem more?

In my first comment I explained you how to move to the next 10 or  previous 10 records. So this should work (let you browse to the next/previous records). Use Datamodule1.Table1.First and Datamodule1.Table1.Last for browsing directly to the first and last record of the table. The MoveBy(+10) instruction also stops at the last record if there are not more than 10 records to the end of the table.

So, please explain your problem more, because I don't understand your question.

Zif.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1356758
oops, wasn't meant as an answer, so if it doesn't help you with your problem, just reject it and explain the problem. Zif.
0
 

Author Comment

by:nhdcb2
ID: 1356759
I am sorry for my little explaination!
Because My touch-screen is 17",it must display two dbgrids
in one screen,and that two dbgrids use the same dataset.
When I click the next or prev,The first dbgrid move 10,
and the second dbgrid move next 10.
If I use moveby, that two dbgrids display the same record.
That is not my want.
So I must know the last record that is displayed in the first dbgrid to transfer to the second dbgrid.
Can you tell me how can I do that?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1356760
mmmm, not so easy to get it I guess. You find a way to detect how many rows are in the dbgrid.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1356761
Let brainstorm a little bit :

 So, if we know how many rows or on the grid.
 And we know what the first record is in the grid
 then we also know the last record.

 We could let the user start with Ttable1.First and if this record moves, we always know which one is the first. If the dbgrid is fixed, we know the amount of rows. (Maybe if we know dimensions of grid and dimension of one row, we know the amount of rows) -> We know last record displayed!

Zif.
 
0
 

Author Comment

by:nhdcb2
ID: 1356762
Zif:
    Thanks for your help.
    But I think your answered doesn't work. I know the first grid'first and last record,but how can I control my
second grid.Now suppose let every dbgrid display 10 records.
but how can I make the second dbgrid move and does't affect
the first dbgrid?

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1356763
Hi nhdcb2,

That's in fact really easy. Just take 2 tables, and assign them to the same database table. then take two datasources and two dbgrids. Then the two dbgrids WON'T be synchronised. Browsing through them will be independent from the other one. If you want them to be synchronised then just use table2.gotocurrent(table1).

ZiF.
0
 
LVL 5

Accepted Solution

by:
mayhew earned 200 total points
ID: 1356764
If I understand you right you want the first grid to display rows 1-10 (for example) and the second grid to display rows 11-20.  When you hit the next button, you want the first grid to display rows 11-20 and the second grid to show rows 21-30.  

(Or it might make more sense to press the next button and have grid 1 show rows 21-30 and grid 2 show 31-40.  It doesn't really matter what you're increment is.)

If this is correct, use 2 tables and datasources (like ZiF said) but when you first start the app (or make the tables active, or whatever) do a table2.moveby(10) to get the offset initialized.

Then when the next button is pressed, do a
Table1.Moveby( Table2.Moveby(10) ).  

Moveby returns an integer that represents how many rows were actually traversed.  If you're looking at the fourth row from the end in the second grid and you press the next button, grid 2 will only move 4 rows.  With the above call, grid 1 will also move only 4 rows.

The call for the prev button would be
Table2.moveby( Table1.moveby(-10) )

This will keep your grids moving together but always offset by 10.

Hope this helps!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), 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, f…

895 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

15 Experts available now in Live!

Get 1:1 Help Now