SCHUCla74
asked on
how to sort a dbgrid when clicking on the title?
I want to sort the columns of a dbgrid by clicking on the the column-title as in explorer. I know it is not hard to do, but I can't manage it. Thank you.
I mean OnTitleClick event of TDBGrid.
ASKER
I knew already that. But must I then do a new sql-query with the order set to that field I clicked on ? Could you give me an code exeample ?
It depends on what Dataset you link your DBGrid.Datasource
with.
For example, if this is TTable and it has Index created on the corresponding Field you simple write:
"YourTableName.IndexName:= ThisFieldI ndexName".
Or You can use TTable IndexFieldNames property to do sorting: "YourTableName.IndexFiledN ames:=This FieldName" .
with.
For example, if this is TTable and it has Index created on the corresponding Field you simple write:
"YourTableName.IndexName:=
Or You can use TTable IndexFieldNames property to do sorting: "YourTableName.IndexFiledN
ASKER
I am using a query component and so I have no property IndexFieldName. Sorry.
Then I see two ways:
1.Put a TClientDataSet and TDatasetProvider components on your Form/DataModule and link DatasetProvider with your Query and ClientDataset with DataSetProvider and DataSource
which was linked with Query link with ClientDataSet.
Then you can use TClientDataSet.IndexFieldN ame property for your sorting and you need not to write additional sql-queries.
2.In OnTitleClick event of your DBGrid you rewrite your
query's SQL property indicating the following: order by
"the corresponding Field".
Choose yourself what you like to do.
1.Put a TClientDataSet and TDatasetProvider components on your Form/DataModule and link DatasetProvider with your Query and ClientDataset with DataSetProvider and DataSource
which was linked with Query link with ClientDataSet.
Then you can use TClientDataSet.IndexFieldN
2.In OnTitleClick event of your DBGrid you rewrite your
query's SQL property indicating the following: order by
"the corresponding Field".
Choose yourself what you like to do.
ASKER
I'm sorry but now I have the problem with the second solution to find the " corresponding " Field ? ( I also tried the first example, but I think the second will do the job, if...)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use onTitleClick property.
Sincerely,
Nestorua.