954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

StringGrid component functions

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.

EnderX
Posting Shark
999 posts since Aug 2006
Reputation Points: 483
Solved Threads: 1
 

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

JoetjeF
Junior Poster in Training
67 posts since Jun 2005
Reputation Points: 15
Solved Threads: 3
 

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

wvgoethe
Newbie Poster
5 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 
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 changeRow > 0 by Row >= (Sender as TStringGrid).FixedRows

bye

Micheus
Junior Poster in Training
72 posts since Jun 2006
Reputation Points: 10
Solved Threads: 4
 

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

prpasim
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

prpasim, you should consider to use some kind of virtual table. Take a look at these two links:
-> VirtualTable Component Overview (already packed)
-> ...make a virtual table (InMemory tables)? (do your self)

best regards

Micheus
Junior Poster in Training
72 posts since Jun 2006
Reputation Points: 10
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You