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

x
?
Solved

TStringGrid - color

Posted on 1999-06-27
1
Medium Priority
?
624 Views
Last Modified: 2008-03-06
Is there any way to set the color of an individual cell of a string grid in response to my codes action ie


if.....then cells[2,5]color := clGreen;
0
Comment
Question by:pady
[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
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 300 total points
ID: 1384768
Hi Pady,

This is a very simplistic way and will get you further. (It colors the cell 'green' when it contains '4'.

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var s: string;
begin
  with (Sender as TStringGrid) do
   if Cells[ACol,ARow] = '4' then begin begin
    with Canvas do begin
      if not (gdSelected in state) then {this is not a selected cell}
       begin
        Pen.Style:=psClear;
        Brush.Style:=bsSolid;
        brush.Color := clGreen;
        {we draw a color rectangle in the cell}
        Rectangle(Rect.Left,Rect.Top,Rect.Right,Rect.Bottom);
        {next we need to put the text}
        s:=(Sender as TStringGrid).Cells[ACol,ARow];
        TextOut(Rect.Left+2,Rect.Top+2,s);
       end;
    end;
   end;
 end;
end;

Regards, Zif
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
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