Solved

StringGrid Column Alignment

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Firewall issues 6 85
Delphi with SQL Natvie Client 15 75
Thread safe  opinion 7 111
Downloading email attachments 2 55
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

21 Experts available now in Live!

Get 1:1 Help Now