Solved

Format StringGrid

Posted on 2002-03-18
7
539 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

14 Experts available now in Live!

Get 1:1 Help Now