Solved

StringGrid Column Alignment

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

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 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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

831 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