• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Stringgrid question

How can i make some columns with numerics (0.00) in a stringgrid so that the justify is right?
  • 2
1 Solution
Hi tzigan,

you need either to draw the cells yourself or you use TListView (note: the first column can only be left aligned).

Perhaps there are third-party controls. Try:

- www.delphipages.com
- www.torry.ru
- delphi.icm.edu.pl (Delphi Super Page)
- www.delphideli.com

Ciao, Mike
tziganAuthor Commented:
Mike,  please give me the code
Which code do you mean? If it is custom draw then use this:

procedure TMainForm.StringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);

  S: String;

   with Sender as TStringGrid do
     S := Cells[ACol, ARow];
     // make the output rectangle a bit smaller to have a small distance from the borders
     InflateRect(Rect, -2, -2);
     // if S is a number then
       DrawText(Canvas.Handle, PChar(S), Length(S), Rect, DT_RIGHT);
     // else
     //   if draw centered then DrawText(Canvas.Handle, PChar(S), Length(S), Rect, DT_CENTER)
     //                    else DrawText(Canvas.Handle, PChar(S), Length(S), Rect, DT_LEFT);

Assign an OnDrawCell handler and leave DefaultDrawing = True to cause the tree to paint selection and focus rectangle.

Ciao, Mike
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now