Board index » delphi » Multiple Lines in StringGrid Cells

Multiple Lines in StringGrid Cells

Is is possible to have more than a single line in a StringGrid cell?
I have tried inserting an ASCII 13 code in the formatting with no
success.  I am trying to have each cell in the first row to display
both the day (ddd) and date (dd/mm/yy) with the day (ddd) being shown
on top of the date.  If I have the date shown as 'Sun 31/05/98' the
cell is too wide for what I want.  I also need each cell content to be
centered in the cell.  Any suggestions?

 

Re:Multiple Lines in StringGrid Cells


Geoff Woodrow <g.wood...@police.vic.gov.au> wrote in article
<3570d81b.86530...@news.ozonline.com.au>...

Quote
> Is is possible to have more than a single line in a StringGrid cell?
> I have tried inserting an ASCII 13 code in the formatting with no
> success.  I am trying to have each cell in the first row to display
> both the day (ddd) and date (dd/mm/yy) with the day (ddd) being shown
> on top of the date.  If I have the date shown as 'Sun 31/05/98' the
> cell is too wide for what I want.  I also need each cell content to be
> centered in the cell.  Any suggestions?

1. set the DefaultRowHight property to a value that makes room for 1 line,
and the RowHeights[0] property to a value that makes enough room for 2
lines
2. create an event handler for the OnDrawCell event. In this handler you
write the text in the cell the way you want it. If you keep the
DefaultDrawing to True, the other cells will be drawn the way they are now
(which is what you want, I presume). The handler has as arguments the
column and row co-ordinates of the cell that needs drawing + the rect of
the cell. Then do something along the following lines:

if Row  = 0 then with MyStringGrid.Canvas do begin
        TextOut(....); // line 1
        TextOut(...); // line 2
end;

Use the Rect to position the text correctly on the stringgrid canvas. Use
the TextHeight and TextWidth properties of the canvas to get the heigth and
width of the text in pixels. Use these + the Rect-values to centre the text
in the cell, if you wish.

Wim

Re:Multiple Lines in StringGrid Cells


In article <3570d81b.86530...@news.ozonline.com.au>,
  g.wood...@police.vic.gov.au (Geoff Woodrow) wrote:

Quote

> Is is possible to have more than a single line in a StringGrid cell?
> I have tried inserting an ASCII 13 code in the formatting with no
> success.  I am trying to have each cell in the first row to display
> both the day (ddd) and date (dd/mm/yy) with the day (ddd) being shown
> on top of the date.  If I have the date shown as 'Sun 31/05/98' the
> cell is too wide for what I want.  I also need each cell content to be
> centered in the cell.  Any suggestions?

      Set DefaultDrawing:= False and write an OnDrawCell event handler.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading

Other Threads