Solved

Changing selection bar color in DBGrid

Posted on 1999-01-20
5
331 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
[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
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
creating threads in delphi 1 201
Delphi: ForceDirectory plain function 7 85
TEMBEDDEDWB how can i change its user agent ? 8 105
Firemonkey Listview item popup menu ? 1 73
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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