Board index » delphi » Sorting data in TdbGrid

Sorting data in TdbGrid

Hi all

How could I impliment that if user clicks on a column heading in dbGrid that
the data in the grid sorts after that column

thanks

Haukur

 

Re:Sorting data in TdbGrid


This is a very simple example:

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
     with Query1 do
    begin
        Close;
        Sql.Clear;
        Sql.Add('Select * from YourTable order by ' +  Column.FieldName);
        Open;
    end;
end;

Haukur ?rn Harearson <hau...@simi.is> wrote in message
news:8a53rb$67n7@bornews.borland.com...

Quote
> Hi all

> How could I impliment that if user clicks on a column heading in dbGrid
that
> the data in the grid sorts after that column

> thanks

> Haukur

Re:Sorting data in TdbGrid


There is an event named OnColumnTitleClick (I think). You can use the Column
parameter of the method to control sorting
for example:

...
case column.index of
  0: <order by the name of the field associated with the column 0 >
  1: <order by the name of the field associated with the column 1 >
  ...
end;
...

or you can use a third-party component (QuantumGrid I think or any other -
see various Delphi sites) that implements this feature...

Haukur ?rn Harearson <hau...@simi.is> az albbiakat rta a k?vetkez?
hrzenetben: 8a53rb$6...@bornews.borland.com...
| Hi all
|
| How could I impliment that if user clicks on a column heading in dbGrid
that
| the data in the grid sorts after that column
|
| thanks
|
| Haukur
|
|

Other Threads