Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TStringGrid component functions

Status
Not open for further replies.

CHeighlund

Programmer
Jun 11, 2007
163
US
I'm trying to work with a TStringGrid where part of the output will be financial values. I've looked at everything I can think of in the help, and tried to track down docs online, but I can't seem to find anything on how to right-justify a TStringGrid column. I know it has to be something obvious that I'm missing, but I don't know what.

Would someone here please offer a useful site url or document url dealing with the TStringGrid function? Something that I can use to try tracking down this information?

Thank you for your consideration.
 
I got this from somewhere on this Forum.
I believe it was in one of the FAQs.
It goes in the [blue]TStringGrid.DrawCell[/blue] procedure:
Code:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
 var
  text: string;
  WidthOfText: integer;
  WidthOfCell: integer;
  LeftOffset: integer;

 begin
  with datagrid do begin
   text := Cells[ACol,ARow];
   WidthOfText := Canvas.TextWidth(text);
   WidthOfCell := ColWidths[ACol];
   LeftOffset := WidthOfCell - WidthOfText;
   Canvas.TextRect(Rect,Rect.Left+LeftOffset-5,Rect.Top,text);
  end; [green]// end with[/green]
 end;

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
Yes, it was from a FAQ on this forum.
faq102-3514

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top