Recent

Author Topic: How to find out who is Sender of TDBGrid OnTitleClick event handler?  (Read 371 times)

Vodnik

  • Full Member
  • ***
  • Posts: 184
I'm using DBgrid's OnTitleClick event for sorting purposes, as described here:
https://wiki.lazarus.freepascal.org/Grids_Reference_Page#Sorting_columns_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?
« Last Edit: January 08, 2021, 08:36:23 pm by Vodnik »

Lutz Mändle

  • Jr. Member
  • **
  • Posts: 56
Re: How to find out who is Sender of TDBGrid OnTitleClick event handler?
« Reply #1 on: January 08, 2021, 07:57:12 pm »
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

  • Full Member
  • ***
  • Posts: 184
Re: How to find out who is Sender of TDBGrid OnTitleClick event handler?
« Reply #2 on: January 08, 2021, 09:24:21 pm »
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...

 

TinyPortal © 2005-2018