Store scrollbars in Delphi dbgrid (even when resizing)

For our dbgrid, we want the scroll bars to be permanently hidden. Since TDBGrid does not have the "scrollbars" property, we use:

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

However, when you resize the window (and the panel containing dbgrid), for the second scrollbars appear and become hidden again only after reminding the two above methods.

The solution is to call these methods in DrawColumnCell, but this causes the dbgrid to flicker, even if DoubleBuffered is set to true.

Is there a way to hide scrollbars forever?

Thanks in advance!

+8
delphi scrollbar c ++ builder dbgrid c ++ builder-xe
source share
3 answers

Hiding the TDBGrid scrollbar in CreateParams has a very short time effect. There procedure UpdateScrollBar , which causes the scrollbar to be visible. This is because the visibility of the scroll bar is controlled by the data displayed, therefore this procedure is called whenever the data changes.

And since this procedure is called whenever the scroll bar needs to be updated and because it is virtual, the time to redefine it. The following code example uses an embedded class, so all TDBGrid components in the form belonging to this device 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. 
+6
source share

The scrollbar is updated in TDBGrid.UpdateScrollBar . Unfortunately, this procedure is not virtual (at least in D7). As part of this procedure, SetScrollInfo is called, a Windows function that does not send a message that may be intercepted. Bad luck.

The only possibility is to override the message handler for the message that is sent whenever the control is resized:

 type TDBGrid = class(DBGrids.TDBGrid) private procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED; end; procedure TDBGrid.WMWindowPosChanged(var Message: TWMWindowPosChanged); begin inherited; Windows.ShowScrollBar(Handle, SB_VERT, False); end; 

Although the UpdateScrollBar also called when the data changes or when the properties of the Active dataset change, it seems to work here without flickering.

+1
source share

Perhaps overriding the CreateParams() method and removing WS_HSCROLL and WS_VSCROLL bit form makes a difference. You can try to do this with class helper if you do not want to write a custom descendant.

You can also use the SetWindowLongPtr API with GWL_STYLE to change the window's style, but then the changes are lost when the grid window is recreated for some reason (so this is not as reliable as overriding CreateParams ).

0
source share

All Articles