[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Format StringGrid

Posted on 2002-03-18
7
Medium Priority
?
580 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Accepted Solution

by:
SteveWaite earned 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses

834 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