Solved

DBGrid Color Change

Posted on 2004-04-29
5
558 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

23 Experts available now in Live!

Get 1:1 Help Now