Solved

Changing selection bar color in DBGrid

Posted on 1999-01-20
5
320 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
Comment Utility
Edited text of question
0
 
LVL 5

Expert Comment

by:heathprovost
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

12 Experts available now in Live!

Get 1:1 Help Now