DBGridEh实现单击标题栏排序方法
2006-02-04 14:05:46 来源:WEB开发网核心提示: 1.添加引用:DBClient2.置DBGridEh控件属性: 设置dghAutoSortMarking属性为true 设置希望排序的Column的TitleButton属性为true3.//表格排序过程PRocedure OrderGrid(dataSet:TClientDataset;orderField:s
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);
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);
更多精彩
赞助商链接