?
Solved

StringGrid

Posted on 2001-08-24
4
Medium Priority
?
251 Views
Last Modified: 2010-04-04
I want to highlight certain cells in a string grid so I toggle font.color, the problem is that the whole grid color is set to the color of the last cell.
That's the whole grid, even cells written to before the color is toggled, ands even in the fixed Row 0.
What am I doing wrong?

0
Comment
Question by:frog
[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
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
vladh earned 200 total points
ID: 6421217
frog,

try this:

procedure TForm1.DemoGridDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  dx : integer;
begin
  With (Sender as TStringGrid) do
  begin
  // Show Text Right-aligned, Text rechtsbundig setzen
    if (ARow = 0) and
       (Acol = 0) then
    With Canvas do
    begin
      FillRect(Rect);
      Text := cells[Acol,Arow];
      dx := TextWidth(Text) + 2;
      TextOut(Rect.Right-dx,Rect.Top,Text);
    end;

  // Set the Color, Feld-Farbe setzen
    case aCol of
      0 : canvas.brush.color := clBlack;
      1 : canvas.brush.color := clMaroon;
      2 : canvas.brush.color := clGreen;
      3 : canvas.brush.color := clOlive;
      4 : canvas.brush.color := clNavy;
    end;
    canvas.textrect (rect,rect.left+2,rect.top+2,cells[acol,arow]);
  end;
end;


 
code courtesy DelphiSwissCenter - nice collection of useful tips there.

http://www.swissdelphicenter.ch/en

Vlad
0
 

Expert Comment

by:eshipman
ID: 6436512
What is the criteria for highlighting the cells?

That is the key to making sure that the other cells
do not get highlighted in the code above.
0
 

Author Comment

by:frog
ID: 6444346
Thanks for your replies vladh and eshipman.
Sorry for not replying earlier, I've had to put my efforts elsewhere for a while.

The grid is only 6 columns wide and holds strings of only a word or two per cell mainly entered at run time. Cells with  entries out of bounds and some cells in one column calculated at run time need to be highlighted to indicate any cells needing attention such as an empty cell, a cell with an invalid date, etc.
It's such a small task that I decided to use a string grid.

I seem to continually come up against this same type of problem, ie expecting objects to be 'fully functional' instead of the 'half baked' things that Delphi seems to contain.
Nothing meant against you personally vladh, but your solution almost duplicates the whole string grid in terms of writing into and highlighting cells.
The grid can already highlight individual cells and even whole rows when they receive focus from the mouse, .... so all I want to know is the syntax to do it.
Is it ...
grid.highlight := clBlue;
cells[c, r].highlight := true;
Or perhjaps it's cells[c, r].lightup  .. etc .... I've tried all the combinations I can think of.
The properties and methods to highlight cells are already a part of the internal workings of the grid so I just want to access them, not duplicate them.


0
 

Author Comment

by:frog
ID: 6514471
Thanks vladh, sorry for the delay I've had a few distractions.


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

719 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