Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
I wrote one, primarily for Oracle datasets, but all it did was parse
and change the "order by" clause to the column that you clicked then
refreshed the query. Clicking the same column again added a "desc"
clause to that.
Grillix
What you must have foremost in mind when asking this question is the fact
that a TDBGrid does not contain any data. It is merely a conduit to make
available to the end-user the data from a dataset component (TTable,
TQuery, etc.).
Now you can force the associated dataset to change its sort order from the
interface of the grid, but you are subject to the capabilities and
limitations of the type of dataset component used. For instance, the only
way to sort data accessed via a TTable is through an index. This means that
custom sorting based on clicking a column ot column title in a grid
requires that you either have an index for each column or that you create a
temporary index on-demand.
With an SQL statement executed from a TQuery, on the other hand, you are
not quite so bound by available indexes. You could rewrite the SQL
statement (or at least the ORDER BY line) and re-execute the query to
produce a result set sorted in the new order.
In Delphi terms, you could provide this capability in a handler for the
OnTitleClick event of the TDBGrid. To this event handler Delphi passes a
TColumn value that is a reference to the clicked column. You could then use
the TColumn.Title.Caption property to get the name of the field for the
column clicked. With that information, you can either build a temporary
index or rewrite the ORDER BY clause of an SQL statement.
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
Field: String;
begin
Field := Column.Title.Caption;
with Query1 do begin
Close;
SQL[2] := 'ORDER BY ' + Field;
Open;
end;
end;
//////////////////////////////////////////////////////////////////////////
Steve Koterski "There are two kinds of pedestrians...the
Technical Publications quick and the dead."
INPRISE Corporation -- Lord Thomas Robert Dewar
http://www.borland.com/delphi (1864-1930)
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
Table1.IndexFieldNames := Column.Title.Name;
end;
Sorting is not matter for visual component like DBGrid. You need sort on
database server.
--
With best regards, Mike Shkolnik.
FIDO: 2:463/106.14
E-Mail: mshk...@rs-ukraine.kiev.ua
mi...@woccu.freenet.kiev.ua
WEB: http://www.geocities.com/SiliconValley/Grid/3989
michele пишет в сообщении <7iuvii$mtm$1...@nnrp1.deja.com> ...
>I need an improved DBGrid that sorts its data just by
>clicking on the coloumn headers, in Microsoft Explorer's
>style.
>I need a low price component or better a free one....
>Do you think I'm I asking too much?
>
>