Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing selection bar color in DBGrid

Posted on 1999-01-20
5
Medium Priority
?
335 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 100 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 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