Solved

how to use next and prev page in dbgrid?

Posted on 1998-07-01
13
483 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

756 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