I like to know how I can sort DBGrid colums by clicking the title?
I am using a paradox table.
Thx,
Juha Kuronen
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...
Tortorelli,Gustavo <gus...@optionsnet.com.br> wrote in message
news:3a657485_2@dnews...
>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;
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...
I will try to create index...
Tortorelli,Gustavo <gus...@optionsnet.com.br> wrote in message
news:3a66c8d8_1@dnews...