Solved

StringGrid Column Alignment

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

615 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