RE:Expandir celda de TStringGrid
Este es un método que alguna vez escribí para tal efecto. Está hecho para Delphi 2006, pero supongo que funcionará en cualquiera. Debe estar ligado al evento OnDblClick de tu StringGrid.
procedure TfrmCatalogos.StringGrid1DblClick(Sender: TObject);
var
rAnt: TRect;
oMousePt: TPoint;
nRow, nCol, nWidth, nWidthMax: Integer;
begin
oMousePt := Mouse.CursorPos;
oMousePt := StringGrid1.ScreenToClient(oMousePt);
for nCol := 1 to StringGrid1.ColCount - 1 do
begin
rAnt := StringGrid1.CellRect(nCol,0);
if (oMousePt.X >= rAnt.Right - 3) and
(oMousePt.X <= rAnt.Right + 4) and
(oMousePt.Y in [rAnt.Top..rAnt.Bottom]) then
begin
nWidthMax := 0;
for nRow := 0 to (StringGrid1.RowCount - 1) do begin
if nRow = 0 then //El header es bold
StringGrid1.Canvas.Font.Style := [fsBold]
else //Las demás líneas no son bold
StringGrid1.Canvas.Font.Style := [];
nWidth := StringGrid1.Canvas.TextWidth(StringGrid1.Cells[nCol, nRow]);
if nWidth > nWidthMax then
nWidthMax := nWidth;
end;
StringGrid1.ColWidths[nCol] := nWidthMax + 5;
end;
end;
end;
Si tu StringGrid presenta imágenes podría no funcionar como esperas, pero sólo tendrías que cuidar que las columnas ocupen algo más de espacio para poner dicha imagen.
Espero que te sirva.
Saludos.