Solved

StringGrid

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now