Solved

Changing selection bar color in DBGrid

Posted on 1999-01-20
5
327 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now