How to find out who is Sender of TDBGrid OnTitleClick event handler? lazarus / 16-Databases ---------------------------------------------------------------------- Vodnik · 2021-01-08 17:03 I'm using DBgrid's OnTitleClick event for sorting purposes, as described here: https://wiki.lazarus.freepascal.org/Grids_Reference_Page#Sorting_colum ns_or_rows_in_DBGrid_with_sort_arrows_in_column_header This example works fine. In my application I have several DBGrids and would like to make an universal OnTitleClick procedure, applicable for any DBGrid. Unfortunately, OnTitleClick handler do not provide Sender parameter, so I don't know which DBGrid have initiated it. I have tried OnMouseDown event (which provides the Sender), in principle it can be used, but have disadvantages, e.g. it hits also when user changes the column width or moves the column Please help with ideas how to find out Sender of OnTitleClick event or make this procedure universal? ---------------------------------------------------------------------- Lutz Mändle · 2021-01-08 18:57 The Column parameter has a Grid property which references to the DBGrid where the column resides. If you using FPC 3.2 or newer, the property IndexFieldNames of the underlying dataset can used for sorting (ascending and descending), simply assign a string with the columnfieldnames (separated with semicolons). For descending sorting append a ' DESC' to the individual fieldname (leading space is important). This only sorts the dataset, the sort arrow of the column title has to determined in the manner shown in the wiki example (assigning an imagelist to the grid and set the property Column.Title.ImageIndex accordingly). HTH ---------------------------------------------------------------------- Vodnik · 2021-01-08 20:24 Thanks, Lutz Mändle, you have made my day! I felt that there should be something like this Grid property in TColumn, but couldn't find it by myself...