DBGrid中顯示多行的方法
来源:百度文库 编辑:神马文学网 时间:2024/05/01 12:29:05
【作者】TATSU
【內文】來源:http://delphi.ktop.com.tw/topic.asp?topic_id=45682
Q:
當DBGrid的資料內容長度超過欄寬時,自动换行。象EXCEL中的格式设置中选定自动换行的功能那样。看到过这种方法的实现,但不知道怎么作出来的?
A:
procedure TForm1.FormShow(Sender: TObject);
var
DBGridOptions : TDBGridOptions;
begin
DBGrid1.DefaultDrawing := False ;
//這一段程式碼中,主要設定了
//1) default row height
TStringGrid(DBGrid1).DefaultRowHeight := 70 ;
//2) 還原 heading 的 row height
TStringGrid(DBGrid1).RowHeights[0] := 20 ;
//3) 如果讓用戶可以自行更改 column 的闊度,整個 grid
//的 row height 都會還原,所以都用程式碼 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 ;
fontColor := clBlack ;
end;
DBGrid1.Canvas.Brush.Color := backColor ;
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.Canvas.Font.Color := fontColor ;
//預先縮小秀字的框架範圍,秀字時讓字與框架留有空間
drawRect := Rect ;
InflateRect(DrawRect, -4, -2) ;
case DataCol of
0 : strValue := DataSource1.DataSet.fieldByName('PRODUCT_ID').AsString ;
1 : strValue := DataSource1.DataSet.fieldByName('PRODUCT_DESC').AsString ;
end;
DrawText(DBGrid1.Canvas.Handle,
PChar(strValue),
Length(strValue),
DrawRect,
DT_WORDBREAK) ;
end;
【內文】來源:http://delphi.ktop.com.tw/topic.asp?topic_id=45682
Q:
當DBGrid的資料內容長度超過欄寬時,自动换行。象EXCEL中的格式设置中选定自动换行的功能那样。看到过这种方法的实现,但不知道怎么作出来的?
A:
procedure TForm1.FormShow(Sender: TObject);
var
DBGridOptions : TDBGridOptions;
begin
DBGrid1.DefaultDrawing := False ;
//這一段程式碼中,主要設定了
//1) default row height
TStringGrid(DBGrid1).DefaultRowHeight := 70 ;
//2) 還原 heading 的 row height
TStringGrid(DBGrid1).RowHeights[0] := 20 ;
//3) 如果讓用戶可以自行更改 column 的闊度,整個 grid
//的 row height 都會還原,所以都用程式碼 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 ;
fontColor := clBlack ;
end;
DBGrid1.Canvas.Brush.Color := backColor ;
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.Canvas.Font.Color := fontColor ;
//預先縮小秀字的框架範圍,秀字時讓字與框架留有空間
drawRect := Rect ;
InflateRect(DrawRect, -4, -2) ;
case DataCol of
0 : strValue := DataSource1.DataSet.fieldByName('PRODUCT_ID').AsString ;
1 : strValue := DataSource1.DataSet.fieldByName('PRODUCT_DESC').AsString ;
end;
DrawText(DBGrid1.Canvas.Handle,
PChar(strValue),
Length(strValue),
DrawRect,
DT_WORDBREAK) ;
end;
DBGrid中顯示多行的方法
DBGrid中顯示多行的方法
DBGrid中顯示多行的方法3
的方法
生男生女的方法生男生女的方法
营销方法:餐饮企业促销方法(150种方法的一部分)
教育技术研究方法---科学研究方法的类型
教育技术研究方法---科学研究方法的类型
长高方法-------------------长高的方法有用啊
读书方法与思想方法的思考
驱除脸上雀斑的有效方法方法
【基本方法】书法结构变化的方法
【基本方法】书法结构变化的方法
22条方法优化大脑的方法
【基本方法】书法结构变化的方法
方法:有效快速增长睫毛的方法
上香的方法 合掌的方法 礼拜的方法 礼佛的好处 念佛的方法...
读书的方法
文言文翻译的方法
英语学习的方法
词汇的记忆方法
提高英语听力的方法
英语学习的方法
日共开会的方法