Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (1)


Remove the horizontal and/or vertical scrollbar of a TDBGridGo to Christophe Geers's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
How to get rid of those pesky scrollbars of a TDBGrid when you don't need them
Product:
Delphi 4.x (or higher)
Category:
Component Writing
Skill Level:
Scoring:
Last Update:
05/29/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet HSCROLL VSCROLL Grid CustomGrid TDBGrid Tag scrollbars horizontal vertical horz vert CreateColumns WM_NCCALCSIZE
Times Scored:
3
Visits:
4772
Uploader: Christophe Geers
Company: ANDROME nv
Reference: N/A
 
Question/Problem/Abstract:
How to get rid of those pesky scrollbars of a TDBGrid when you don't need them ?
Answer:



This example component shows how to get rid off the horizontal and/or vertical scrollbar of a TDBGrid. The code can ofcourse be used for other types of grid. I just used a TDBGrid for this example.

You can control the horizontal and vertical scrollbar seperatly. There is
a boolean propery made available for each of the scrollbars. You can ofcourse
control these settings in a more effecient way like using the scrollbars set
property or a set of your own. The removing of the scrollbars is done by
trapping the WM_NCCALCSIZE message. In here you check the style and adjust
it to your need.

This method will work for the most controls which use the common horizontal
scrollbars, but there might be some slight problems with some controls which
work in a slightly different way.

As an added bonus, the code for this example component also shows how to
give each column of the TDBGrid a tag property like most controls have.
This is achieved by derriving a class from TColumn and adding a Tag property
to it. Then all that remains is to override the CreateColumns function of the
TDBGrid and specify that each column that is created is of an object of the
newly created column class.


Tested with Delphi 6 Professional on Windows 2000 Professional.

-------------------------------------------------------------------------------

unit ExtentedDBGrid;

interface

uses
  Windows, Messages, SysUtils, Classes, DBGrids, Math, Controls;

type
  TExtendedColumn = class(TColumn)
  private
    { Private declarations }
    FTag: Integer;
  protected
    { Protected declarations }
  published
    { Published declarations }
    property Tag: Integer read FTag write FTag;
  end;

  TExtendedDBGrid = class(TDBGrid)
  private
    { Private declarations }
    FVerticalBar  : Boolean;
    FHorizontalBar: Boolean;

    procedure SetVerticalBar(AValue: Boolean);
    procedure SetHorizontalBar(AValue: Boolean);
    procedure WMNCCalcSize(var msg: TMessage); message WM_NCCALCSIZE;
  protected
    { Protected declarations }
    function CreateColumns: TDBGridColumns; override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property VerticalBar: Boolean read FVerticalBar write SetVerticalBar default True;
    property HorizontalBar: Boolean read FHorizontalBar write SetHorizontalBar default False;
  end;

procedure Register;

implementation

uses Grids;

procedure Register;
begin
  RegisterComponents('Own Components', [TExtendedDBGrid]);
end;

{ TExtentedDBGrid }

constructor TExtendedDBGrid.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FVerticalBar   := True;
  FHorizontalBar := False;
end;

function TExtendedDBGrid.CreateColumns: TDBGridColumns;
begin
  Result := TDBGridColumns.Create(Self,TExtendedColumn);
end;

destructor TExtendedDBGrid.Destroy;
begin
  inherited Destroy;
end;

procedure TExtendedDBGrid.SetHorizontalBar(AValue: Boolean);
begin
  FHorizontalBar := AValue;
  RecreateWnd;
end;

procedure TExtendedDBGrid.SetVerticalBar(AValue: Boolean);
begin
  FVerticalBar := AValue;
  RecreateWnd;
end;

procedure TExtendedDBGrid.WMNCCalcSize(var msg: TMessage);
var
  style: Integer;
begin
  style := getWindowLong( handle, GWL_STYLE );
  if (style and WS_HSCROLL) <> 0 then
    if not FHorizontalBar then
      SetWindowLong( handle, GWL_STYLE, style and not WS_HSCROLL );
  if (style and WS_VSCROLL) <> 0 then
    if not FVerticalBar then
      SetWindowLong( handle, GWL_STYLE, style and not WS_VSCROLL );
  inherited;
end;

end.

-------------------------------------------------------------------------------





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Horizontal scrollbar
    Nikola Slavic (May 3 2006 11:01AM)

It's not possible to remove both scrollbars, the horizontal is allways there (except when the vertival is visible).
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
A. B. Talal
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)