Solved

DBGrid Color Change

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

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
Comparing dates in Delphi. Greater than/ Less than 3 225
Help on project with Soap 10 57
Correct Component for Shopping Cart. 2 112
Dev Express grid collapse 2 45
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…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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