[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

150pts CustomDBGrid Component

Posted on 2002-06-04
4
Medium Priority
?
154 Views
Last Modified: 2010-04-04
0
Comment
Question by:third
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
bes67 earned 200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

656 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