Solved

how to use next and prev page in dbgrid?

Posted on 1998-07-01
13
448 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
Comment Utility
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
? 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Master Detail with TADODataset 4 94
proper way to parse text with delphi 7 87
Best Firemonkey component pack 1 73
Working with hours 3 31
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

10 Experts available now in Live!

Get 1:1 Help Now