Solved

Scrollbars and TDBGrid

Posted on 1998-08-10
10
1,156 Views
Last Modified: 2012-05-04
How do I synchonise a vertical scroll bar with a TDBGrid so that it actually moves at the same rate as the grid and is proportionally sized??

With a grid full of data that is longer than the display area, clicking on the scrol bar (or the arrows) takes the button on the scroll bar down to half way, where it then stays until the end of the table is reached (where it tests for BOF/EOF I guess).

Is there anyway to get the button the scroll bar to move down the correct amount each time the scroll bar is moved ie. only a little way down if you click on an arrow, a page legth down if you click on the scroll bar, enabling you to drag it to another part of the table.

Also in some apps, the scroll bar button is sized proportionally to the amount of text on the screen...if there is much more text to see the button is smaller, bigger if the text only just goes off of the screen.  Is there any way of achieving this??
0
Comment
Question by:Reality
  • 5
  • 4
10 Comments
 

Author Comment

by:Reality
ID: 1361837
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361838
Reality, can you be more specific? Zif.
0
 

Author Comment

by:Reality
ID: 1361839
Edited text of question
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1361840
Sorry, Reality still don't understand your question. especially with scrollbar button? Which scrollbar button do you mention, you only have arrow-buttons... maybe you can address us to an url with a sample of what you need.

For scrollbar :

 what you can do is placing a scrollbar over the scrollbar of the dbgrid (make this one invisible) and handle the scrollbar yourself :

Scrollbar1:TScrollBar;

Initialization:
Scrollbar1.setparams(0,0,table1.recordcount);

procedure Tform1.DataSource1DataCharge(Sender:TObject;Field:TField);
begin
   scrollbar1.position:=table1.recno;
end

procedure Tform1.ScrollBar1Change(Sender:TObject);
begin
lastscrollposition:=table1.recno;
table1.moveby(Scrollbar1.position-lastscrollposition);
end

not so a fancy solution dough.

Zif.
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1361841
The normal DBGrid doesn't do what you want, and for a good reason. When the cursor is opened the DBGird does not do a record count since this consumes to much time. That is the reason why the scrollbar doesn't show correctly.

You can make a new DBGrid but that requires a lot of work and the new component cannot be used on large tables then because of the time.

Regards Jacco
0
 

Author Comment

by:Reality
ID: 1361842
I had a sneaking suspicion it wouldn't be a simple thing to do! :>

By the button on a scroll bar I mean that thing that moves up and down as you move the scroll bar...I guess a slider would have been a better name, but I didn't think of that name at the time.

Re Jacco...how big is a big table??  I think it'll only be used on a small table, so is there anyway of just replacing the scroll bar on a component and inheriting all the rest??

Thanks.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361843
reality,

'so is there anyway of just replacing the scroll bar on a component and inheriting all the rest??' Yes...

Look at my previous comment. Just make verticle scrollbar invisible and place your own one aside.... then you only change the scrollbar... And you can use any fancy scrollbar too!

Zif.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 150 total points
ID: 1361844
The remove the vertical scrollbar use this code :

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.

No further, use a panel. Put your scrollbar on it (RightAlign). Put the new grid on it. (Align = client).

And use above code (in previous comment) to move scrollbar with grid.

Zif.


0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361845
reality, be sure you use it for small tables only... Otherwise speed will drop significantly
0
 

Author Comment

by:Reality
ID: 1361846
Very fast and very clear.  Thanks for your help...I can now return to my plans!!  Bwahahaha!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 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