Board index » delphi » A Dbgrid with colored cells ?

A Dbgrid with colored cells ?

Dear all,

We are trying to find currently a particular form of component
for Delphi 1.0 (or 2.0) : a DbGrid similar to the standard one,
but which would give us the possibility to change the color of
each of the cells (individually). It would be marvellous if, in
the same time, this grid had drag and drop capabilities
applicated to her cells.

Does somebody know if this special component exist ?
If you work in a company or if you have developped a component
by yourself which looks like this description, we would be more
than happy to see a shareware version of it (and to purchase it
after tests to insure that it is what we search).

Thanks for your attention.

--
Luc Delnondedieu

 

Re:A Dbgrid with colored cells ?


Hi Luc,

All the things you ask for is present in TDBGrid. Just look to the
events, in par. OnDrawDataCell, OnDragDrop,  OnDragOver, OnEndDrag.

Cheers,

Remco

Quote
Luc Delnondedieu <106413.1...@CompuServe.COM> wrote:
>Dear all,

>We are trying to find currently a particular form of component
>for Delphi 1.0 (or 2.0) : a DbGrid similar to the standard one,
>but which would give us the possibility to change the color of
>each of the cells (individually). It would be marvellous if, in
>the same time, this grid had drag and drop capabilities
>applicated to her cells.

>Does somebody know if this special component exist ?
>If you work in a company or if you have developped a component
>by yourself which looks like this description, we would be more
>than happy to see a shareware version of it (and to purchase it
>after tests to insure that it is what we search).

>Thanks for your attention.

>--
>Luc Delnondedieu

Re:A Dbgrid with colored cells ?


Quote
Luc Delnondedieu wrote:
> We are trying to find currently a particular form of component
> for Delphi 1.0 (or 2.0) : a DbGrid similar to the standard one,
> but which would give us the possibility to change the color of
> each of the cells (individually). It would be marvellous if, in
> the same time, this grid had drag and drop capabilities
> applicated to her cells.

I am having the same problem except that I want to have calculated
columns that are updatable

Let you know me anything if you find something ...

Email : JCAST...@VDAB.BE

Greetings

Jan Casteels

Hint : If you do not find something like that you have to change the
OnDrawCell property of a drawgrid and handle everything yourself...

Re:A Dbgrid with colored cells ?


106413.1...@CompuServe.COM (Luc Delnondedieu)  wrote

Quote
> We are trying to find currently a particular form of component
> for Delphi 1.0 (or 2.0) : a DbGrid similar to the standard one,
> but which would give us the possibility to change the color of
> each of the cells (individually). It would be marvellous if, in

This can be achieved with the standard DBGrid if you switch off default  
drawing and control each cell drawing in OnDrawDataCell. Borland has a  
TechInfo for this on their web site.

Quote
> the same time, this grid had drag and drop capabilities
> applicated to her cells.

I would be very much surprised if noone had already written a free DBGrid  
descendant with something like a MouseToCell function. I'd look on the  
Delphi Super Page for it.

Michael
--

Michael Suedkamp                                      m...@suedkm.franken.de

Re:A Dbgrid with colored cells ?


I don't know if this helps, but I could color individual cells in a
DBGrid without having to make a new DBGrid component.  This is what I
just tested....

I created a form, dropped a TTable component it, and pointed it to the
EMPLOYEE.DB database in the DBDEMOS database.  I dropped a Datasource
and DBGrid on the form so that it showed on the form.

I thought a simple test would be, for the employee number in the
EMPLOYEE.DB table, check if it's an odd number.  If it's an odd
number, then turn that cell green.

Then, the only code I attached was to the DBGrid's OnDrawColumnCell
event, which looks as follows....

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:
TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  holdColor: TColor;
begin
  holdColor := DBGrid1.Canvas.Brush.Color; {store the original color}
  if Column.FieldName = 'EmpNo' then {only do for the cell displaying
EmpNo}
    if (Column.Field.AsInteger mod 2 <> 0) then begin
      DBGrid1.Canvas.Brush.Color := clGreen;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      DBGrid1.Canvas.Brush.Color := holdColor;
    end;
end;

This uses the DefaultDrawColumnCell method that is defined with the
TCustomDBGrid component, of which TDBGrid is a child.  This turned
each cell green of an employee whose emp no was odd.

Hope this helps,
Ed

Quote
Luc Delnondedieu <106413.1...@CompuServe.COM> wrote:
>Dear all,
>We are trying to find currently a particular form of component
>for Delphi 1.0 (or 2.0) : a DbGrid similar to the standard one,
>but which would give us the possibility to change the color of
>each of the cells (individually). It would be marvellous if, in
>the same time, this grid had drag and drop capabilities
>applicated to her cells.
>Does somebody know if this special component exist ?
>If you work in a company or if you have developped a component
>by yourself which looks like this description, we would be more
>than happy to see a shareware version of it (and to purchase it
>after tests to insure that it is what we search).
>Thanks for your attention.
>--
>Luc Delnondedieu

Re:A Dbgrid with colored cells ?


Well you won't be surprised then - Borland wrote one!!

... and it is already in TDBGrid (well inherited from TCustomGrid in
Grids.pas)

function TCustomGrid.MouseCoord(X, Y: Integer): TGridCoord;

In TDBGrid it is a protected function.

--
Paul Motyer
***pa...@linuxserver.pccity.com.au*** currently broken
Croydon, Australia, 3136

Quote
> I would be very much surprised if noone had already written a free DBGrid
> descendant with something like a MouseToCell function. I'd look on the  
> Delphi Super Page for it.

> Michael
> --

> Michael Suedkamp                                    

m...@suedkm.franken.de
Quote

Re:A Dbgrid with colored cells ?


If you need DBGrid with colored cells, just visit my home page.

---
Vitaly Furman
E-mail: e...@kharkov.ua
http://www.geocities.com/SiliconValley/1593
=== DO NOT SEND ME BIG FILES WITHOUT AGREEMENT ===

Re:A Dbgrid with colored cells ?


Here's a component that will color a complete row:

By Ludovic Dubois <ldub...@prettyobjects.com> 06 Nov 1996

http://www.prettyobjects.com/RAD/dirafrm.htm
----------------------------------------------------------------------------
-----------------------------------------------
unit ColorGrid;

interface

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

type TColorDataCellEvent = procedure (Sender: TObject; ARow, ACol: Integer;
const Value: string; State: TGridDrawState; var Highlight: Boolean) of
object;

TColorDBGrid = class(TDBGrid)
private { Private declarations } FOnColorDataCell: TColorDataCellEvent;
protected { Protected declarations }
function HighlightCell(DataCol, DataRow: Integer; const Value: string;
AState: TGridDrawState): Boolean; override;

procedure ColorCell(DataCol, DataRow: Integer; const Value: string; AState:
TGridDrawState;
var HighLight: Boolean);
public { Public declarations }
published { Published declarations }
property OnColorDataCell: TColorDataCellEvent read FOnColorDataCell write
FOnColorDataCell;
end;

procedure Register;

implementation

function TColorDBGrid.HighlightCell(DataCol, DataRow: Integer; const Value:
string; AState: TGridDrawState): Boolean;
begin
  Result := inherited HighlightCell(DataCol, DataRow, Value, AState);
  ColorCell(DataCol, DataRow, Value, AState, Result);
end;

{ Mettre HighLight True pour reprendre les couleurs d'une slection }
{ Changer les proprits Canvas.Brush et Canvas.Pen sinon }
procedure TColorDBGrid.ColorCell(DataCol, DataRow: Integer; const Value:
string; AState: TGridDrawState; var HighLight: Boolean);
begin
  if Assigned(FOnColorDataCell) then
     FOnColorDataCell(Self, DataRow, DataCol, Value, AState, HighLight);
end;

procedure Register; begin RegisterComponents('Pretty Objects',
[TColorDBGrid]); end;

end.

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

Luc Delnondedieu <106413.1...@CompuServe.COM> wrote in article
<5c5722$4k...@mhafc.production.compuserve.com>...

Quote
> Dear all,

> We are trying to find currently a particular form of component
> for Delphi 1.0 (or 2.0) : a DbGrid similar to the standard one,
> but which would give us the possibility to change the color of
> each of the cells (individually). It would be marvellous if, in
> the same time, this grid had drag and drop capabilities
> applicated to her cells.

> Does somebody know if this special component exist ?
> If you work in a company or if you have developped a component
> by yourself which looks like this description, we would be more
> than happy to see a shareware version of it (and to purchase it
> after tests to insure that it is what we search).

> Thanks for your attention.

> --
> Luc Delnondedieu

Other Threads