╃ DATA的天空 ╃

                                      -=technology=-

                                                                                DATA vs LONA   天下无双  ^_^                             

 |  |


Delphi 应用技巧两则(DataGrid行间隔改变颜色、DBGridEh实现单击标题栏排序方法)

=====data发表于技术|12:2:0

在DElphi中的DataGrid怎样使它显示的行间隔改变颜色?就向.NET中同名控件一样。
---------------------------------------------------------------

好像是在 OnDrawDataCell 事件中写代码。
---------------------------------------------------------------

procedure TForm1.dbgridDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if DBGrid2.DataSource.DataSet.RecNo mod 2=1 then
begin
DBGrid2.Canvas.Font.Color := clBlue;
DBGrid2.Canvas.Brush.Color:=clyellow;
end
else begin
DBGrid2.Canvas.Font.Color := clred;
DBGrid2.Canvas.Brush.Color:= clGradientActiveCaption;
end;
DBGrid2.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
==========================================================================

DBGridEh实现单击标题栏排序方法
1.添加引用:DBClient
2.置DBGridEh控件属性:
设置dghAutoSortMarking属性为true
设置希望排序的Column的TitleButton属性为true
3.//表格排序过程
procedure OrderGrid(dataSet:TClientDataset;orderField:string);
var
i:integer;
begin
if dataSet.IndexFieldNames<>'' then
begin
i:=TClientDataSet(DataSet).IndexDefs.IndexOf('i'+orderField);
if i=-1 then
begin
with Dataset.IndexDefs.AddIndexDef do
begin
Name:='i'+orderField;
Fields:=orderField;
DescFields:=orderField;
end;
end;
dataSet.IndexFieldNames:='';
dataSet.IndexName:='i'+orderField;
end
else
begin
dataSet.IndexName:='';
dataSet.IndexFieldNames:=orderfield;
end;
end;
4.在DBGridEh的OnTitleClick事件中调用
OrderGrid(DM.ClientDataset,Column.FieldName);





{CommentAuthor}【评 论】 -----{CommentTime}

{CommentEmail} {CommentUrl} {CommentIp}

{CommentContent}

流逝的时光

最 新 评 论

友 情 链 接

搜 索

DATA 最新的 20 条日志

 


2004 Copyright by {lionellai}  Powered by {5DBlog.com}