在DBgridEH的控件里,点击列标题排序
procedure DBGridEh1TitleSort(Column: TColumnEh; AQuery:TUniQuery);
var
sortstring: string;
begin
with Column do
begin
if FieldName =''then Exit
else
begin
if Title.SortMarker = smNoneEh then
begin
title.sortMarker:=smDownEh; //在bgrideh的控件里,点击列标题会自动改变箭头的
sortstring := FieldName +' DESC'; //ASC和DESC前面加空格,否则会报错
AQuery.IndexFieldNames := sortstring; //uniquery需要用这种方法
end
else
begin
if title.SortMarker = smDownEh then
begin
title.sortMarker:=smUpEh;
sortstring := FieldName +' ASC';
AQuery.IndexFieldNames := sortstring;
end
else
if title.SortMarker = smUpEh then
begin
title.sortMarker:=smDownEh;
sortstring := FieldName +' DESC';
AQuery.IndexFieldNames := sortstring;
end;
end;
end;
end;
end;
调用方法:
procedure TForm1.DBGridEh1TitleClick(Column: TColumnEh);
begin
//UniQuery1.IndexFieldNames := Column.FieldName;
DBGridEh1TitleSort(Column,UniQuery1);
end;