EhLib
ContentsIndexHome
PreviousUpNext
TCustomDBGridEh.OnSortMarkingChanged Property

Occurs after changing sortmarker property in any Title of Columns.

Pascal
property OnSortMarkingChanged: TNotifyEvent;

Write an OnSortMarkingChanged event handler to take specific action after changing sortmarker property value in any Title of Columns. You can use it to change order by section in SQL text of TQuery component and reopen it. In handler you can access to sortmarked columns via SortMarkedColumns property. 

 

Example 

 

procedure TForm1.DBGridEh1SortMarkingChanged(Sender: TObject);
var i :Integer;
    s:String;
    Actived: Boolean;
begin
  s := '';
  for i := 0 to DBGridEh1.SortMarkedColumns.Count-1 do
   if DBGridEh1.SortMarkedColumns[i].Title.SortMarker = smUpEh then
     s := s + DBGridEh1.SortMarkedColumns[i].FieldName + ' DESC , '
   else
     s := s + DBGridEh1.SortMarkedColumns[i].FieldName + ', ';
  if s <> '' then s := ' ORDER BY ' + Copy(s,1,Length(s)-2);
  Actived := Query1.Active;
  Query1.SQL.Strings[Query1.SQL.Count-1] := s;
  if Actived then
  begin
    Query1.Close;
    Query1.Open;
  end;
end;
Copyright (c) 1998-2013. All rights reserved.
What do you think about this topic? Send feedback!