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

How to sort DBGrid columns by clicking title?

1,001 views
Skip to first unread message

Jusa

unread,
Jan 17, 2001, 4:50:17 AM1/17/01
to
Hi!

I like to know how I can sort DBGrid colums by clicking the title?
I am using a paradox table.

Thx,

Juha Kuronen


Tortorelli,Gustavo

unread,
Jan 17, 2001, 5:29:27 AM1/17/01
to
Hi Juha,

I use this code below:

ontitleclick:
begin
if column.Field.FieldKind = fkLookup then
begin
if
table.IndexDefs.GetIndexForFields(column.Field.KeyFields,false) <> Nil then
table.indexname :=
table.indexdefs.getIndexForFields(column.Field.KeyFields,false).Name
else
table.indexname := '';
end
else begin
if column.Field.FieldKind = fkdata then
begin
if
table.IndexDefs.GetIndexForFields(column.FieldName,false) <> Nil then
table.indexname :=
tbmain.indexdefs.getIndexForFields(column.FieldName,false).Name
else
table.indexname := '';
end
else
table.indexname := '';
end;end;

"Jusa" <Juha.K...@Miragel.fi> escreveu na mensagem
news:3a656ae2_2@dnews...

Jusa

unread,
Jan 17, 2001, 7:19:25 AM1/17/01
to
Thanks Gustavo, but I didnt get that code working correctly. When I clicked
title
happened that my dbgrid came empty. Do use two tables (table and tbmain) or
what?

Tortorelli,Gustavo <gus...@optionsnet.com.br> wrote in message
news:3a657485_2@dnews...

Otto Porter

unread,
Jan 18, 2001, 12:49:33 AM1/18/01
to
On Wed, 17 Jan 2001 14:19:25 +0200, "Jusa"
<Juha.K...@Miragel.fi> wrote:

>Thanks Gustavo, but I didnt get that code working correctly. When I clicked
>title
>happened that my dbgrid came empty. Do use two tables (table and tbmain) or
>what?
>

Try this instead, it is not as complicated. You do need to
create an index (secondary-maintained) for each field which
you want to sort on, Then you change the index as indicated
below.

As you can see the TitleClick event gives you the Column
which has been clicked.


procedure TFormCustSelect.DBGridTitleClick(Column: TColumn);
var
ColNum : integer;
begin

ColNum := Column.ID;
case ColNum of
0:
begin
DMod2.TblCustSelect.IndexName := 'MU_';
end;
2:
begin
DMod2.TblCustSelect.IndexName := 'CitySt_';
end;
end;
end;

Tortorelli,Gustavo

unread,
Jan 18, 2001, 5:41:27 AM1/18/01
to
Sorry,

I use only one table. The name of component table in my application is
TBMAIN.
TBMAIN and TTABLE is the same.

In the example you need, of course, create index in your table paradox (DB)

If you have problem, please, write again.

Gustavo

BTW: Sorry my English wrong


"Jusa" <Juha.K...@Miragel.fi> escreveu na mensagem

news:3a658dd6_2@dnews...

Jusa

unread,
Jan 19, 2001, 8:47:04 AM1/19/01
to
OK. Thanks Gustavo!!!

I will try to create index...


Tortorelli,Gustavo <gus...@optionsnet.com.br> wrote in message

news:3a66c8d8_1@dnews...

0 new messages