Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep the scrollbars hidden in a Delphi dbgrid (even on resize)

For our dbgrid we want the scrollbars to be constantly hidden. Since TDBGrid doesn't have a 'scrollbars' property, we use:

ShowScrollBar(DBGrid1.Handle, SB_VERT, False);
ShowScrollBar(DBGrid1.Handle, SB_HORZ, False);

However when we resize the window (and the panel containing the dbgrid), for a second the scrollbars appear and becom hidden again only after recalling the two above methods.

A solution is to call these methods in DrawColumnCell, but this causes flickering of the dbgrid, even with DoubleBuffered set to true.

Is there any way to hide the scrollbars permanently?

Thanks in advance!

like image 656
user729103 Avatar asked Sep 23 '11 13:09

user729103


People also ask

How do I resize the scroll bar?

Resize the Horizontal Scroll BarPlace the mouse pointer over the vertical ellipsis (three vertical dots) next to the horizontal scroll bar. The mouse pointer changes to a double-headed arrow. Drag to the right to shrink the horizontal scroll bar or drag to the left to enlarge the scroll bar.

What are the two types of scrollbars?

There are two types of scroll bars: vertical and horizontal.

What is the working of scrollbars option?

A scroll bar's orientation determines the direction in which scrolling occurs when the user operates the scroll bar. A horizontal scroll bar enables the user to scroll the content of a window to the left or right. A vertical scroll bar enables the user to scroll the content up or down.

Why do I have two vertical scrollbars?

You're basically getting a double scrollbar because your giving the body min-height of 100vh AND setting an overflow. It appears this was done to keep the menu in the correct position on mobile devices.


1 Answers

Hiding the scrollbar of the TDBGrid in CreateParams has a very short time effect. There's the procedure UpdateScrollBar which causes the scrollbar to be visible. It happens because the scroll bar visibility is controlled depending on the data displayed, thus this procedure is called whenever the data is changed.

And since this procedure is called whenever the scrollbar needs to be updated and because it's virtual, it's time to override it.
The following code sample uses the interposed class, so all TDBGrid components on the form which belongs to this unit will behave the same:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TDBGrid = class(DBGrids.TDBGrid)
  private
    procedure UpdateScrollBar; override;
  end;

type
  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TDBGrid.UpdateScrollBar;
begin
  // in this procedure the scroll bar is being shown or hidden
  // depending on data fetched; and since we never want to see 
  // it, do just nothing at all here
end;

end.
like image 98
TLama Avatar answered Sep 17 '22 17:09

TLama