Recent

Author Topic: Adding a button to DBGrid Title row at draw time  (Read 3283 times)

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Adding a button to DBGrid Title row at draw time
« on: December 28, 2018, 04:56:35 pm »
Hi,

Could someone point me in the right direction on how to add a button to the title columns in a DBGrid (I want to add a filter button to each column) at draw time.

I know how to add custom controls to fields, but can't quite figure out how to only add a control to the title row. I'm guessing it's easy, just need a pointer in the right direction,

Thanks
Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Adding a button to DBGrid Title row at draw time
« Reply #1 on: December 28, 2018, 05:37:16 pm »
Don't know if possible.
The only thing I can think of is using OnDrawColumnCell to draw a Button on the title cell and OnTitleClick to implement the action.

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Adding a button to DBGrid Title row at draw time
« Reply #2 on: December 28, 2018, 06:48:42 pm »
Hi garlar77,

Thanks for the pointer, I'll give that a go although can't I use the OnClick event of the button to do what I need?

Just one other quick question, how can I detect if it is the Title Cell, whiuch was my real query as I only know how to draw cells on all row?

Thanks.
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Adding a button to DBGrid Title row at draw time
« Reply #3 on: December 28, 2018, 07:10:52 pm »
Just one other quick question, how can I detect if it is the Title Cell, whiuch was my real query as I only know how to draw cells on all row?

Use DBGrid.CellToGridZone(). The result type is declared in grids.pas as:
Code: Pascal  [Select][+][-]
  1. type TGridZone = (
  2.   gzNormal,            
  3.   gzFixedCols,         
  4.   gzFixedRows,         
  5.   gzFixedCells,        
  6.   gzInvalid            
  7. );
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Adding a button to DBGrid Title row at draw time
« Reply #4 on: December 28, 2018, 07:41:07 pm »
Many thanks lucamar
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Adding a button to DBGrid Title row at draw time
« Reply #5 on: December 29, 2018, 03:31:34 pm »
Hi,

So CellToGridZone requires two parameters, Col (which I can get) and Row which I'm not sure how I get? I thought about using the dataset row, but of course that doesn't indicate a header row! Any pointers?

Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Adding a button to DBGrid Title row at draw time
« Reply #6 on: December 31, 2018, 01:42:10 am »
Anyone??
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

 

TinyPortal © 2005-2018