Solved

Scrollbars and TDBGrid

Posted on 1998-08-10
10
1,137 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
Comment Utility
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Reality, can you be more specific? Zif.
0
 

Author Comment

by:Reality
Comment Utility
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Reality
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
reality, be sure you use it for small tables only... Otherwise speed will drop significantly
0
 

Author Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

13 Experts available now in Live!

Get 1:1 Help Now