哈哈,我刚解决这个问题,给全分啊:
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var desf:String; i:integer;
begin
with ClientDataSet1.IndexDefs do
begin
i:=ClientDataSet1.IndexDefs.IndexOf('dataset_index');
if i>=0 then
if ClientDataSet1.IndexDefs.Items.Fields=Column.FieldName then
if ClientDataSet1.IndexDefs.Items.DescFields='' then
desf:=Column.FieldName;
Clear;
with AddIndexDef do
begin
Name:='dataset_index';
Fields:=Column.FieldName;
DescFields:=desf;
end;
end;
if ClientDataSet1.IndexName='dataset_index' then
ClientDataSet1.DeleteIndex('dataset_index');
ClientDataSet1.IndexName:='dataset_index';
end;