jinzhili的专栏

为爱奋斗

DBGrid单击标题自动排序

procedure TForm1.DBGrid1TitleClick(Column: TColumn); var s,cFieldName:string; i:integer; DataSet:TDataSet; begin Try DataSet:=Column.Grid.DataSource.DataSet; if not DataSet.Active then exit; if Column.Field.FieldKind=fkLookup then cFieldName:=Column.Field.KeyFields else if Column.Field.FieldKind=fkCalculated then cFieldName:=Column.Field.KeyFields else cFieldName:=Column.FieldName; if DataSet is TCustomADODataSet then begin s:=TCustomADODataSet(DataSet).Sort; if s='' then begin s:=cFieldName; end else begin if Pos(cFieldName,s)<>0 then begin i:=Pos('DESC',s); if i<=0 then begin s:=s+' DESC'; end else begin Delete(s,i,4); end; end else begin s:=cFieldName; end; end; TCustomADODataSet(DataSet).Sort:=s; end else if DataSet is TClientDataSet then begin if TClientDataSet(DataSet).indexfieldnames<>'' then begin i:=TClientDataSet(DataSet).IndexDefs.IndexOf('i'+Column.FieldName); if i=-1 then begin with TClientDataSet(DataSet).IndexDefs.AddIndexDef do begin Name:='i'+Column.FieldName; Fields:=Column.FieldName; DescFields:=Column.FieldName; end; end; TClientDataSet(DataSet).IndexFieldNames:=''; TClientDataSet(DataSet).IndexName:='i'+Column.FieldName; end else begin TClientDataSet(DataSet).IndexName:=''; TClientDataSet(DataSet).IndexFieldNames:=column.fieldname; end; end; Except End; end;
阅读更多
文章标签: dataset integer string
个人分类: Delphi
想对作者说点什么? 我来说一句

pb单击标题栏对数据窗口排序

2012年05月28日 7KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭