Solved

StringGrid Column Alignment

Posted on 2000-03-30
3
1,837 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

Industry Leaders: 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

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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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