Solved

StringGrid Column Alignment

Posted on 2000-03-30
3
1,888 Views
Last Modified: 2010-05-18
Hey Gang,

I need help in setting the alignment of cells within a particular column. Can any help and include a code snipet?

Thanks,
Chad
0
Comment
Question by:dhertzfe
[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
3 Comments
 

Accepted Solution

by:
kwang080897 earned 100 total points
ID: 2672053
I Think You Have to Draw the Columm your selfes like this.

Set The Stringgrids Property:
DefaultDrawing = False

and try this code:


procedure TForm1.FormCreate(Sender: TObject);
begin
  // Some data in Colums
  Stringgrid1.Cells[1,1]:='A';
  Stringgrid1.Cells[1,2]:='B';
  Stringgrid1.Cells[2,2]:='C';
  Stringgrid1.Cells[2,1]:='D';
  Stringgrid1.Cells[3,2]:='E';
  Stringgrid1.Cells[3,1]:='F';
end;




procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
 Txt : String;
begin
  With Stringgrid1.Canvas do
  Begin;
    if (ARow=0) or (ACOl=0) then Brush.Color:=ClSilver
      Else  Brush.Color:=ClWhite;
    Txt:=StringGrid1.Cells[ACol,ARow];
    Case ACol of
      //1 = Left ALignment
      //2 = Center Alignment
      1 : TextRect(Rect,Rect.Right-TextWidth(txt),Rect.Top,txt);
      2 : TextRect(Rect,Rect.Left+Round((REct.Left-Rect.Right/2)-(TextWidth(txt)/2)),Rect.Top,txt)
      Else TextRect(Rect,Rect.Left,Rect.Top,txt);
    End;
    if GDFocused in State then DrawFocusRect(Rect);
  End;  
end;


Regards

Kim
0
 

Expert Comment

by:perkley
ID: 2672061
Try this component, it comes with the source code, and it will give you an idea of how to implement this.

TStringAlignGrid V2.0

Search for "String Grid Align"
http://www.delphipages.com

or for direct download -

http://www.delphipages.com/edit/count.cfm?ID=1172
0
 

Author Comment

by:dhertzfe
ID: 2678652
Thanks Kim;

Your example worked just fine.

Chad
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 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