DBGrid列标题单击多列排序 [数据库教程]

database

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列标题单击多列排序

以上是 DBGrid列标题单击多列排序 [数据库教程] 的全部内容, 来源链接: utcz.com/z/535098.html

回到顶部