naxxtreme.blogg.se

Delphi ado query sort lookup
Delphi ado query sort lookup




Note: the code above uses typed constants to preserve the value of the previously "selected" column for sort order.You can search against any active table or query using the Locate and Lookup methods. begin if is TCustomADODataSet then with TCustomADODataSet() do begin tryĭ.Style :=ĭ.Style. Procedure TForm1.DBGrid1TitleClick(Column: TColumn)

delphi ado query sort lookup

And finally, when we sort the dataset by another column we want to remove the mark from the previously selected column.įor the sake of simplicity, to mark the column that "sorts" the records we'll simply change the font style of the column title to Bold, and remove it when dataset is sorted using another column. Next, if we click on a column title and the dataset is already sorted by that column we want to change the sort order from ASC (ascending) to DESC (descending) and vice versa. The code, as always, extends the idea.įirst we want to, in some way, mark the column that is currently used for sort order. The Sort property is the widestring value indicating the "ORDER BY" part of the standard SQL query – of course you do not need to write the SQL query to be able to use the Sort property.īelow you can find the code for the OnTitleClick even handler that sorts the records by column click. If you are using ADO approach to Delphi database development, and want to sort the records in the dataset, you need to set the Sort property of your AdoDataset (ADOQuery, AdoTable). SORT ON COLUMN CLICK? CHANGE FONT OF THE SORT COLUMN TITLE?

delphi ado query sort lookup

(Sender: TObject Shift: TShiftState X, Y: Integer) The code below simply uses the MouseCoord property of the DBGrid component to "calculate" where the mouse pointer is – if over DGBrid title area, the pt.y equals 0, which is the first row in the DBGrid – the title area (displaying column/field titles). All you have to do is to add the code to the OnMouseMove event for the DBGrid component.

delphi ado query sort lookup

All the component names were left as Delphi named them when dropped on the form (DBGrid1, ADOQuery1, AdoTable1, …)įirst, let's see how to change the mouse pointer while it moves over the DBGrid title area.






Delphi ado query sort lookup