Link to home
Start Free TrialLog in
Avatar of nhdcb2
nhdcb2

asked on

how to use next and prev page in dbgrid?

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?
Avatar of nhdcb2
nhdcb2

ASKER

Edited text of question
To move 10 records forward, use :

DM1.Table1.MoveBy(+10);

To move 10 records backward, use :

DM1.Table1.MoveBy(-10);

Zif.
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.
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.
Avatar of nhdcb2

ASKER

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!
? 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.
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.
Avatar of nhdcb2

ASKER

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?
mmmm, not so easy to get it I guess. You find a way to detect how many rows are in the dbgrid.
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.
 
Avatar of nhdcb2

ASKER

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?

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.
ASKER CERTIFIED SOLUTION
Avatar of mayhew
mayhew

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