Recent

Author Topic: TDateCellEditor: a date editor for grids  (Read 287 times)

EganSolo

  • Full Member
  • ***
  • Posts: 213
TDateCellEditor: a date editor for grids
« on: March 01, 2021, 09:52:46 am »
I'd like to add a custom date editor by leveraging TDateEdit found on the Misc palette. My challenge is to get the editor to respond to VK_DOWN, VK_UP, etc. I know of two ways that work (column 0 and 2 in my project), one that doesn't work (column 1) and a fourth that should work but doesn't  ::)
  • Approach #1 -- works: Set KeyPreview to true and handle the OnKeyDown event of the form. That's what happens in column 0 of the grid in the attached project. This approach works so long I don't turn the class that I am working on and that descends from Tgrid into a component.
  • Approach #2 -- Doesn't work: Follow the example project GridCellEditor in the examples folder of Lazarus (C:\Lazarus\Examples\GridExamples\GridCellEditor). This is illustrated in Column 1 of my project: the date editor doesn't handle vk_DOWN and if you press the down arrow, you'll see that you're stuck.
  • Approach #3 -- Works: Handle the TDateEdit OnKeyDown event. That's a relatively straightforward approach that works and is illustrated in Column 2
  • Approach #4 -- Should work but doesn't: I then studied the Grids unit and saw that this was not the approach that was chosen. Instead, specialized components were created to better interact with the grid. I followed that approach and created a specialized DateEdit descendant (there is no TCustomDateEdit), but I can't get that class to receive messages or reach to them. As you'll see if you run the project, clicking on a cell in Column 3, the editor shows-up but it doesn't handle the VK_Down.

    Two questions:
    • 1: Is the approach in the Grids unit superior to handling the events of the editors?
    • 2: Do you have any suggestion that would allow the TDateCellEditor to receive messages?

    Your feedback is truly appreciated!

jamie

  • Hero Member
  • *****
  • Posts: 4468
Re: TDateCellEditor: a date editor for grids
« Reply #1 on: March 02, 2021, 12:55:09 am »
my guess is its a composite control which means you aren't seeing the TEDIT part of the TDATEedit but the control it lives on.

I didn't look at the source so I can only bet that its a TPanel.

In which case the TEDIT has the focus and you aren't getting jack!

I suppose the TEDIT part could of called the KeyDown but it looks like it maybe calling the OnKeyDown event instead to emulate a key press for user code..

 Instead of overriding the KeyDown implement a OnKeyDown that carries the (Sender:.....) and set it...
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018