const
txt: string = '';
zeile: integer = 1; // z.B.
spalte: integer = 2; // z.B.
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (zeile = arow) and (spalte = acol) then begin
inc(rect.left, 2);
drawtext(Tstringgrid(sender).canvas.handle, pchar(txt), length(txt),
rect, DT_WORDBREAK);
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
x, br, hh, it: integer;
begin
if listbox1.items.count = 0 then exit;
stringgrid1.cells[spalte, zeile] := '';
hh := stringgrid1.canvas.textheight(listbox1.items[0]) *
listbox1.items.count + 2;
br := 0;
for x := 0 to listbox1.items.count - 1 do begin
it := stringgrid1.canvas.textwidth(listbox1.items[x]) + 4;
if it > br then br := it;
end;
txt := listbox1.items.text;
if stringgrid1.colwidths[spalte] < br then
stringgrid1.colwidths[spalte] := br;
if stringgrid1.rowheights[zeile] < hh then
stringgrid1.rowheights[zeile] := hh;
// --- falls die Zelle markiert sein soll ---
stringgrid1.row := zeile;
stringgrid1.col := spalte;
// -------------------------------------------
end;