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

x
?
Solved

DBGrid Color Change

Posted on 2004-04-29
5
Medium Priority
?
569 Views
Last Modified: 2010-04-05
I need that when the user enters a row in the DBGrid that row changes to a different color like 'clInfoBk'. I need the whole row and not just the Collumn Cell.
0
Comment
Question by:ramoreia
[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
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10949495
If You do not need dgEditing Option for dbgrid You can set
dgRowSelect to True
0
 
LVL 8

Expert Comment

by:BdLm
ID: 10949612
dbgrid1.columns[1].color := clInfoBk;


0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 10949676
Set dgRowSelect to true in Option then

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin
if gdselected in state then
    TDBGrid(Sender).Canvas.Brush.Color :=  clInfoBk
    else
    TDBGrid(Sender).Canvas.Brush.Color := clWindow;
  TDBGrid(Sender).DefaultDrawDataCell(Rect, Field, State);
end;
0
 
LVL 17

Accepted Solution

by:
mokule earned 200 total points
ID: 10949733
In case You do not want to set dgRowSelect to True Try this.
Table1 is DBgrid DataSet

var
  vsel: Variant;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if DBGrid1.DataSource.DataSet.FieldByName('YourKeyField').Value = vsel then
    DBGrid1.Canvas.Brush.Color := clRed;
  DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
begin
  vsel := DataSet.FieldByName('YourKeyField').Value;
end;
0
 
LVL 8

Expert Comment

by:BdLm
ID: 10949952
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

722 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