Solved

Format StringGrid

Posted on 2002-03-18
7
540 Views
Last Modified: 2010-04-05
Hello guys!

How do I format each unique row of a StringGrid ?

Example: how can I alternate white and gray rows in a list put in a StringGrid (five rows: white, gray, white, gray, white) ?

Also, how can I NOT get the selected blue highlight when I click on the grid ?

At last, how can I align a single cell ?

Thanks!
0
Comment
Question by:qas
7 Comments
 

Expert Comment

by:Kelmi
ID: 6878501
You can use TStringGrid's OnDrawCell event. Look Delphi Help to get a pretty good example.
0
 

Author Comment

by:qas
ID: 6878721
well...
I managed to code something near OK with Canvas.FillRect(Rect) stuff but there is a little problem:  I can't put text in there since it paints the whole cell...

any help ?
Thanks
0
 

Author Comment

by:qas
ID: 6878737
Let me get you some more precisions...

I want to paint the background of some cells but be able to put some text in it.

Thanks again
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 3

Accepted Solution

by:
SteveWaite earned 200 total points
ID: 6878898
procedure TMyStringGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
var
  TheCellText: String;
  Index: Boolean;
begin
  Index := ((ACol = Col) and (ARow = Row));
  with ARect, Canvas do
  begin
    try
      if (Index and (Pos((IntToStr(Acol) + ':' + IntToStr(ARow)), FOffCells) = 0))
        then Font.Color := clHighlightText
        else Font.Color := clWindowText;
    except
      Font.Color := clWindowText;
    end;
    if ((ARow <> 0) and (ACol <> 0) and (Pos((IntToStr(Acol) + ':' + IntToStr(ARow)), FOffCells) > 0)) then
    begin
      Brush.Style := bsSolid;
      Brush.Color := clBtnFace;
      FillRect(ARect);
    end;
    if (Index and (Pos((IntToStr(Acol) + ':' +IntToStr(ARow)), FOffCells) = 0)) then
    begin
      Brush.Style := bsSolid;
      Brush.Color := clHighlight;
      FillRect(ARect);
    end;
    TheCellText := Cells[ACol, ARow];
    TextRect(ARect, Left + (Right - Left - TextWidth(TheCellText)) div 2, Top + (Bottom - Top - TextHeight(TheCellText)) div 2, TheCellText);
  end;
end;

any help?
0
 

Expert Comment

by:asburgoyne
ID: 6880602
Why not use the TStringAlignGrid component available free from www.hoerstemeier.com - it allows all of what you have asked and an awful lot more.

Adam
0
 

Author Comment

by:qas
ID: 6882890
Thanks Steve! Worked fine!
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6883080
Great! I thought that may help you to suss it out!
Best Wishes,
Steve
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

815 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

8 Experts available now in Live!

Get 1:1 Help Now