?
Solved

Format StringGrid

Posted on 2002-03-18
7
Medium Priority
?
558 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
[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
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
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!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 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