Solved

StringGrid

Posted on 2001-08-24
4
246 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
  • 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

Industry Leaders: 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

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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

685 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