dbgrideh中文本多行显示问题

来源:百度知道 编辑:UC知道 时间:2024/06/28 03:15:33
我的数据库中有文本型字段,每字段最多可有50个汉字,请问在dbgrideh中如何多行显示出该字段中的所有文字(列宽已确定)?

procedure TForm1.FormShow(Sender: TObject);
var
DBGridOptions : TDBGridOptions;
begin

DBGrid1.DefaultDrawing := False ;
//这一段代码码中,主要设定了如下三项内容:
//1) 默认行高
TStringGrid(DBGrid1).DefaultRowHeight := 70 ;

//2) 还原 heading 的行高
TStringGrid(DBGrid1).RowHeights[0] := 20 ;

//3) 若允许用户自行更改列宽,整个 grid的
// 行高就都会还原,所以需要disable用户调整列宽。
DBGridOptions := DBGrid1.Options ;
Exclude(DBGridOptions,dgColumnResize) ;
DBGrid1.Options := DBGridOptions ;
end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
drawRect : TRect ;
StrValue : String ;
backColor, fontColor : TColor ;
begin
if gdSelected in State then
begin
backColor := clNavy ;
fontColor := clWhite ;
end
else
begin
backColor := clWhite ;