Solved

DBGrid Color Change

Posted on 2004-04-29
5
561 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
  • 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 22

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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

15 Experts available now in Live!

Get 1:1 Help Now