TTable 控件怎么实现 DBGrid的单击标题排序
如果你采用ADO,那么这是很简单的:
ADOTable1.Sort:=DBGrid1.Columns[Column.Index].FieldName;
在OnTitleClick事件中调用就可以了
Procedure OW_OrderADOGrid(Column: TColumn);
Var
DataSet: TDataSet;
FieldNames:String;
Begin
if not Column.Field.DataSet.Active then abort;
if not (Column.Field.FieldKind in [fkData,fkLookup]) then exit;
DataSet := Column.Field.DataSet;
if Column.Field.Lookup then
FieldNames:= Column.Field.KeyFields
else
FieldNames:=Column.Field.FieldName;
if DataSet is TCustomADODataSet then
with TCustomADODataSet(DataSet) do
begin
if (Pos(FieldNames, Sort) = 1) and (Pos(' DESC', Sort) = 0) then
Sort := FieldNames + ' DESC' else
Sort := FieldNames + ' ASC';
end;
end;