Does anyone know of a good site or doc that describes the ways to use a TStringGrid? I'm trying to figure out how to right-justify some of the items that are going to be placed into a TStringGrid, and none of the docs I've found so far seem to have anything on how to do that.

Recommended Answers

All 5 Replies

You might find this tip useful. Google on 'tstringgrid align' gives many more examples.

I think actually you can't. but there are some other ways of getting such a control.

For example you can 'ownerdraw' a TListView (Win32 Palette), you just set the property ViewStyle to vsReport and OwnerDraw to true.

Ownerdraw allows you to change not only the alignment but also visual style and more.

If you want some information about ownerdrawing and how to make a TListView act like a TStringGrid just ask me or private message me.

johann

Member Avatar for Micheus

Does anyone know of a good site or doc that describes the ways to use a TStringGrid? I'm trying to figure out how to right-justify some of the items that are going to be placed into a TStringGrid

You'll need write some code on StringGrid's OnDrawCell event.

Just a sample, to write right aligned text on the second column:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer; Rect: TRect; State: TGridDrawState);
var
  X, C, R :Integer;
begin
  C := Col; R := Row;  // it believes is necessary, if use "with" below
  if (Col = 2) and (Row > 0) then
  with Sender as TStringGrid do
  begin
    X := Rect.Left +(Rect.Right -Rect.Left) -Canvas.TextWidth(Cells[C, R]) -3;
    Canvas.TextRect(Rect, X, Rect.Top +2, Cells[C, R]);
  end;
end;

- basically you need calc the start x pos of the text on rect to be paint, using text and rect width;
- Col=0 and Row=0 are fixed column and row. Maybe you can change Row > 0 by Row >= (Sender as TStringGrid).FixedRows

bye

Hi guys i need help i need to display information from a saved file to the string grid on delphi?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.