Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sorting DBGrids

46 views
Skip to first unread message

michele

unread,
May 31, 1999, 3:00:00 AM5/31/99
to
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?


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

michele

unread,
May 31, 1999, 3:00:00 AM5/31/99
to
I need an improved DBGrid that sorts its dataset just by

michele

unread,
May 31, 1999, 3:00:00 AM5/31/99
to

michele

unread,
May 31, 1999, 3:00:00 AM5/31/99
to

grillix

unread,
May 31, 1999, 3:00:00 AM5/31/99
to

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

michele

unread,
May 31, 1999, 3:00:00 AM5/31/99
to

Steve Koterski

unread,
Jun 1, 1999, 3:00:00 AM6/1/99
to
On Mon, 31 May 1999 23:31:17 +0200, "michele" <ros...@tin.it> wrote:

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)

ri...@my-deja.com

unread,
Jun 2, 1999, 3:00:00 AM6/2/99
to
In article <37550de3.5313078@newslist>,

skot...@NOSPAMinprise.com wrote:
> On Mon, 31 May 1999 23:31:17 +0200, "michele" <ros...@tin.it> wrote:
>
> >I need an improved DBGrid that sorts its dataset 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?
>
For a table you can use something like this

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
Table1.IndexFieldNames := Column.Title.Name;
end;

Ray Hall

unread,
Jun 4, 1999, 3:00:00 AM6/4/99
to
Posting from michele <ros...@tin.it> includes [ article was <7iuuk5$j8
r$1...@fe1.cs.interbusiness.it>]

>I need an improved DBGrid that sorts its dataset 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?
>
You don't need a component if your grid is fed by a table rather than a
query. Change the index and you get exactly what you are after. check on
the Grid's events
--
Ray Hall
r...@ashworth.demon.co.uk

Mike Shkolnik

unread,
Jun 7, 1999, 3:00:00 AM6/7/99
to
Download a freeware TSMDBGrid component from my site.
This component may draw a "sort" arrow on column title but you need sort a
dataset - in OnTitleClick event switch a IndexName for TTable or generate a
SELECT-statement with new ORDER BY-clause for TQuery.

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?
>
>

Solly Monama

unread,
Jun 7, 1999, 3:00:00 AM6/7/99
to
Hi,

try http://www.tmssoftware.com/

michele wrote in message <7iuvii$mtm$1...@nnrp1.deja.com>...

Solly Monama

unread,
Jun 7, 1999, 3:00:00 AM6/7/99
to
0 new messages