Solved

StringGrid

Posted on 2001-08-24
4
249 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 50 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

628 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