DBGridEh实现单击标题栏排序方法

王朝delphi·作者佚名  2006-01-09
宽屏版  字体: |||超大  

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);

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有