Solved

DBGrid in d3

Posted on 1998-02-09
2
188 Views
Last Modified: 2010-04-04
How do i change a (non selected) row's color in a DBGrid component?

How can I do this automatically, based on a specific field's value?

e.g. I want all employee's records in an grid to be shown in red if the employee is a manager.
0
Comment
Question by:kyriacos
  • 2
2 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1358808
The row in red or the font in red?
0
 
LVL 5

Accepted Solution

by:
ronit051397 earned 100 total points
ID: 1358809
Connect the DBGrid to the COUNTRY.DB from the DBDEMOS and write the following:


procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin
  if not (gdSelected in State) then
  with DBGrid1.Canvas do
  begin
    if Table1.FieldbyName('Continent').Value='North America' then
    begin
      brush.Color:=clRed;
      font.Color:=clWhite;
    end
    else
    begin
      brush.Color:=clWhite;
      font.Color:=clBlack;
    end;
      FillRect(Rect);
      TextOut(Rect.Left,Rect.Top,Field.Value);
  end;
end;
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

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…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 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