Solved

150pts CustomDBGrid Component

Posted on 2002-06-04
4
151 Views
Last Modified: 2010-04-04
0
Comment
Question by:third
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
bes67 earned 50 total points
ID: 7055531
Hi

Try this unit. This is JUST an example. PicDBGrid inherited from DBGrid and publish two properties Picture and PictureFieldName (to determine where to draw picture). Note that in the cell assotiated with this field just picture will be drawn, not the query data

unit PicDBGrid;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids;

type
  TPicDBGrid = class(TDBGrid)
  private
    { Private declarations }
    FPicture: TPicture;
    FPictureFieldName: string;
    procedure SetPicture(Value: TPicture);
  protected
    { Protected declarations }
    procedure DrawColumnCell(const Rect: TRect; DataCol: Integer; Column: TColumn;
                             State: TGridDrawState); override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Picture: TPicture read FPicture write SetPicture;
    property PictureFieldName: string read FPictureFieldName write FPictureFieldName;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TPicDBGrid]);
end;

{ TPicDBGrid }

constructor TPicDBGrid.Create(AOwner: TComponent);
begin
  inherited;
  FPicture := TPicture.Create;
end;

destructor TPicDBGrid.Destroy;
begin
  FPicture.Free;
  inherited;
end;

procedure TPicDBGrid.DrawColumnCell(const Rect: TRect; DataCol: Integer;
  Column: TColumn; State: TGridDrawState);
begin
  inherited;
  if AnsiCompareText(Column.FieldName, PictureFieldName) = 0 then
    with Canvas do
    begin
      StretchDraw(Rect, FPicture.Bitmap);
    end;
end;

procedure TPicDBGrid.SetPicture(Value: TPicture);
begin
  FPicture.Assign(Value);
end;



end.
0
 
LVL 30

Author Comment

by:third
ID: 7055654

Great, that did it exactly what i want! could you post your answer on the link i've given above so i can give you all the points.

btw, i have additional request. could it be possible to add a property that will control the spaces between the rows.

i have tried the code below but i'm not so sure if that's the right way to do it. it destroys the appearance of the image (i.e. not proportionally sized).

procedure TPicDBGrid.DrawColumnCell(const Rect: TRect; DataCol: Integer;
 Column: TColumn; State: TGridDrawState);
var
 OutRect : TRect;
begin
 inherited;
 if AnsiCompareText(Column.FieldName, PictureFieldName) = 0 then
   with Canvas do
   begin
     OutRect := Rect;
     InflateRect(OutRect,-2,-2);
     StretchDraw(OutRect, FPicture.Bitmap);
   end;
end;

thanks again! ;-)
0
 
LVL 1

Expert Comment

by:bes67
ID: 7056287
I have posted on given link and ... take a look on Indent property

0
 
LVL 30

Author Comment

by:third
ID: 7058161
here's the bonus... thanks again! ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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