关闭

DBGrid单击标题自动排序

标签: datasetintegerstring
851人阅读 评论(0) 收藏 举报
分类:
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;
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:167859次
    • 积分:2462
    • 等级:
    • 排名:第14997名
    • 原创:73篇
    • 转载:13篇
    • 译文:0篇
    • 评论:25条
    文章分类