大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说DBGrid列标题单击多列排序[通俗易懂],希望您对编程的造诣更进一步.
procedure TfrmUnionShipMent.dgMainTitleBtnClick(Sender: TObject;
ACol: Integer; Column: TColumnEh);
VAR
INDEX : INTEGER;
SortString : String;
FirstFlag : boolean;
SortFieldName: string;
begin
inherited;
if adqMain.Active then
begin
// if (not TADODataSet(TDBGridEh(Sender).DataSource.DataSet).Active)
// or (TADODataSet(TDBGridEh(Sender).DataSource.DataSet).RecordCount<=0) then
// Abort;
// {实现排序}
// if Column.Field.FieldKind = fkLookup then
// SortFieldName := Column.Field.KeyFields
// else
// SortFieldName := Column.FieldName;
//
// if TADODataSet(TDBGridEh(Sender).DataSource.DataSet).Sort = SortFieldName then
// begin
// TADODataSet(TDBGridEh(Sender).DataSource.DataSet).Sort := SortFieldName + ‘ DESC‘;
// Column.Title.SortMarker := smDownEh;
// end
// else
// begin
// TADODataSet(TDBGridEh(Sender).DataSource.DataSet).Sort := SortFieldName;
// Column.Title.SortMarker := smUpEh;
// end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
SortString := ‘‘;
if Column.Title.SortMarker <> smUpEh then
Column.Title.SortMarker := smUpEh
else
Column.Title.SortMarker := smDownEh;
FOR INDEX := 1 TO dgMain.SortMarkedColumns.Count DO
if dgMain.SortMarkedColumns[INDEX – 1].Title.SortMarker = smDownEh then
begin
SortString := SortString + dgMain.SortMarkedColumns[INDEX – 1].FieldName + ‘ DESC ‘+‘,‘;
end
else
begin
SortString := SortString + dgMain.SortMarkedColumns[INDEX – 1].FieldName + ‘ ASC ‘+‘,‘;
end;
if (adqMain.RecordCount > 0) and (Trim(SortString)<>‘‘) then
begin
// TADODataSet(TDBGridEh(Sender).DataSource.DataSet).Sort := copy(SortString,1,Length(SortString)-1);
adqMain.Sort := copy(SortString,1,Length(SortString)-1);
end;
end;
end;
DBGrid列标题单击多列排序
原文地址:https://www.cnblogs.com/zhou0811/p/13451510.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/6824.html