首页  编辑  

change the DefaultRowHeight of a TDBGrid?

Tags: /超级猛料/VCL/Grid控件/   Date Created:

change the DefaultRowHeight of a TDBGrid?

// 1. Way: Derive a new Type: TMyDBGrid

type

 TMyDBGrid = class(TDBGrid)

 public

   property DefaultRowHeight;

 end;

var

 Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);

begin

 DbGrid1.Canvas.Font.Size := 13;

 TMyDBGrid(DBGrid1).DefaultRowHeight := DBGrid1.Canvas.TextHeight('MMMMM') + 4;

end;

// 2. Way: Make a TypeCast:

procedure TForm1.Button1Click(Sender: TObject);

begin

 DBGrid1.DataSource.DataSet.DisableControls;

 TStringGrid(DBGrid1).DefaultRowHeight := 55;

 DBGrid1.DataSource.DataSet.EnableControls;

end;