unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, JvExGrids, JvStringGrid;
type
TForm2 =
class(TForm)
JvStringGrid1: TJvStringGrid;
procedure JvStringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure SetMaxRowHeight(AGrid: TJvStringGrid; ARow: Integer);
const
cAddHeight = 4;
var
lTextHeigth: Integer;
lMaxRowHeight: Integer;
liZ1: Integer;
lBitmap: TBitmap;
lText:
String;
lRect: TRect;
begin
lMaxRowHeight := AGrid.DefaultRowHeight;
lBitmap := TBitmap.Create;
lBitmap.Canvas.Font := AGrid.Font;
for liZ1 := 0
to AGrid.ColCount - 1
do
begin
lText := AGrid.Cells[liZ1, ARow];
lTextHeigth := DrawText(lBitmap.Canvas.Handle, PChar(lText), Length(lText), lRect, DT_WordBreak
or DT_NOCLIP) + cAddHeight;
if (lTextHeigth > lMaxRowHeight)
then
begin
lMaxRowHeight := lTextHeigth;
end;
end;
lBitmap.Free;
if (AGrid.RowHeights[ARow] <> lMaxRowHeight)
then
begin
AGrid.RowHeights[ARow] := lMaxRowHeight;
end;
end;
procedure TForm2.JvStringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
lText:
String;
lGrid: TJvStringGrid;
begin
lGrid := TJvStringGrid(Sender);
lText := lGrid.Cells[ACol, ARow];
lGrid.Canvas.FillRect(Rect);
Dec(Rect.Left, -2);
Inc(Rect.Right, -2);
Dec(Rect.Top, -2);
Inc(Rect.Bottom, -2);
DrawText(lGrid.Canvas.Handle, PChar(lText), Length(lText), Rect, DT_WordBreak);
SetMaxRowHeight(lGrid ,ARow);
end;
end.