Delphi7 TMS TDBAdvGrid Sort data when column header is clicked

Andrei picture Andrei · Apr 19, 2011 · Viewed 7.6k times · Source

I'm a newbie into Delphi and i need an advice.

I'm using a TMS TDBAdvGrid and i need to sort the data when the user is clicking the header of a column. I setup the sort settings of the grid and i write code for the onclicksort event, but it is not working.

The sort settings of the grid:

 SortSettings.Show = True;
 SortSettings.IgnoreBlanks = True;
 SortSettings.BlankPos = blLast;

the onclicksort event:

 try
     try
       if FSortISWorking then
         Exit;
       FSortISWorking := true;

       if ACol < 0 then
       begin
         grid.BeginUpdate;
         grid.SortSettings.Column := ACol;
         Application.ProcessMessages;
         grid.QSort;
         grid.EndUpdate;
       end;
     except on e: Exception do
       begin
         // log the error
       end;
     end; 
     finally
      FSortISWorking := false;  
     end;

The grid is not linked directly to the database. The data is loaded into memory (TClientDataSet) and i need to sort the data only in memory, without another query to the database.

Thank you

Answer

Heinrich Ulbricht picture Heinrich Ulbricht · Apr 19, 2011

I tried your example and this solved the issue for me:

Grid.PageMode := False;