StringGrid cells multiline

Posted by Jose C P15709 on December 03, 20010

In Reply to Word Wrap StringGrid posted by James Krawczyk on December 03, 20010

: Hi All

: I'm trying to create an application that does file hashing when you drag and drop the files onto it. To keep the design looking clean and since it has multiple hashes it returns I'm using a StringGrid to display the results. However the hash for SHA-512 and Whirlpool are (obviously) 512bit hashes and the resulting string is too long to fit into a StringGrid cell.

: Is there any way to make the cell accept something past the limit (I've already tried increase that collum size to it's max). Or is there a simple way to make the StringGrid Word Wrap the hash results?

: The code the puts the result into the grid is

: if Form1.CheckWhirl.Checked = True then
: Begin
: Form1.StringGrid1.Cells[1,cell] := (SHAWhirlFileGen(hashfile,11));
: Form1.Stringgrid1.Cells[0,cell] := 'Whirpool Hash:';
: End;

: Thanks
----------------------------

In my Delphi examples stringgrid is named "grid" and long strings are in second column.
To make entire cell visible, you have several possibilities.

1. Make stringgrid column wider, in object inspector or in code when the form is showed:

procedure TForm1.FormShow(Sender: TObject);
begin
  Grid.ColWidths[0] := 80; 
  Grid.ColWidths[1] := 500; // second column
end;

2. Or show more lines in cell when stringgrid is drawn. In ondrawcell event:

procedure TForm1.GridDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if ACol = 1 then begin 
    Grid.Canvas.FillRect(Rect); 
    Grid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, Copy(Grid.Cells[1, ARow], 1, 32));
    Grid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, Copy(Grid.Cells[1, ARow], 32, 64));
  end;
end;

Experiment with row height and column width. Suggest: Arial 8 point, second column width 220, stringgrid defaultrowheight 33.

Good luck!
Jose C.

Related articles

       

Follow Ups