Solved

Changing selection bar color in DBGrid

Posted on 1999-01-20
5
329 Views
Last Modified: 2010-04-04
I got this code from the Inprise web page, but when I run it, I get an access violation.  Any ideas why? I am using Delphi v3.0

type
   TCustomDBGridCracker = class(TCustomDBGrid);
                           
var
   Cracker: TCustomDBGridCracker;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
          const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
     
begin
   with Cracker(Sender) do
      if DataLink.ActiveRecord = Row - 1 then
         Canvas.Brush.Color := clRed
      else
         Canvas.Brush.Color := clWhite;
   DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
0
Comment
Question by:Gressmm1
5 Comments
 

Author Comment

by:Gressmm1
ID: 1362498
Edited text of question
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 1362499
Shouldnt it be like this:

begin  
   with TCustomeDBGridCracker(Sender) do
        ^^^^^^^^^^^^^^^^^^^^^
      if DataLink.ActiveRecord = Row - 1 then
         Canvas.Brush.Color := clRed
      else
         Canvas.Brush.Color := clWhite;
   DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

Heath
0
 
LVL 3

Expert Comment

by:Ronald Buster
ID: 1362500
Hi,

Try this maybe a solution to your problem. Just simple place a dbgrid component to
your form (eg dbgrid1 in this case)

And use following code into the drawdatacell procedure;

this works for me,

regards,

Cono

<--------------------------------------->

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
begin
    if gdSelected in State then
      DBGrid1.Canvas.Brush.Color := clBlue
    else
      DBGrid1.Canvas.Brush.Color := clWhite;
  DBGrid1.DefaultDrawDataCell(Rect,Field,State);
end;

0
 

Author Comment

by:Gressmm1
ID: 1362501
A little more clarification may be necessary.  Your code works fine for coloring just the
selected CELL.  What I want to do, is color the entire ROW that the selected cell is in, but I do not want to us the dgRowSelect property of the dbgrid.
0
 
LVL 9

Accepted Solution

by:
ginsonic earned 50 total points
ID: 1362502
You can use the RXDBGrid component .
It is what you need .
If you send me your address I send you the component and a shot example .
Nick
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
Create Database on Android via Delphi dbExpress 3 116
Delphi Firemonkey Need Sample for Online Shopping Example. 2 168
LAN or WAN ? 11 96
can't find the executable in Simulator 1 101
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

820 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