I am having problems changing the sort order on a DBgrid at runtime (I am using paradox tables). I have pre-defined an index for each field I wish to sort on (in ascending order).
I can change which column to sort on by clicking in the column title without problems, but changing the order does not work.
I have stepped through my code and the index definition is getting changed correctly but it seems to lose the change when the Indexdefs are updated or the table is reopened. Here is my routine that is called from the OnTitleClick event.
procedure TTimeSeriesForm.Descend(DoDescending: boolean; Column: TColumn);
var
I: Integer;
begin
CatGrid.DataSource.DataSet.DisableControls;
with Datamodule2 do
begin
CSR.Close;
for I := 0 to CSR.IndexDefs.Count - 1 do
if (CSR.IndexDefs.Items.Fields = Column.FieldName) then
begin
if (Not DoDescending) then
CSR.IndexDefs.Items.DescFields := ''
else
CSR.IndexDefs.Items.DescFields := Column.FieldName;
CSR.IndexName := CSR.IndexDefs.Items.Name;
end;
CSR.Open;
end;
CatGrid.DataSource.DataSet.EnableControls;
end;
Thank RonR
I can change which column to sort on by clicking in the column title without problems, but changing the order does not work.
I have stepped through my code and the index definition is getting changed correctly but it seems to lose the change when the Indexdefs are updated or the table is reopened. Here is my routine that is called from the OnTitleClick event.
procedure TTimeSeriesForm.Descend(DoDescending: boolean; Column: TColumn);
var
I: Integer;
begin
CatGrid.DataSource.DataSet.DisableControls;
with Datamodule2 do
begin
CSR.Close;
for I := 0 to CSR.IndexDefs.Count - 1 do
if (CSR.IndexDefs.Items.Fields = Column.FieldName) then
begin
if (Not DoDescending) then
CSR.IndexDefs.Items.DescFields := ''
else
CSR.IndexDefs.Items.DescFields := Column.FieldName;
CSR.IndexName := CSR.IndexDefs.Items.Name;
end;
CSR.Open;
end;
CatGrid.DataSource.DataSet.EnableControls;
end;
Thank RonR