Solved

Format StringGrid

Posted on 2002-03-18
7
538 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

15 Experts available now in Live!

Get 1:1 Help Now