Recent

Author Topic: [SOLVED]DBGRID : How to trigger an action when leaving a cell?  (Read 636 times)

micoudic

  • New Member
  • *
  • Posts: 30
[SOLVED]DBGRID : How to trigger an action when leaving a cell?
« on: September 20, 2023, 09:33:59 am »
Good morning

I would like to execute an action when leaving a cell, and only when leaving the cell. How to proceed ?
There are indeed the events:
- OnCellClick: but if I enter the cell using the TAB key?
- OnColEnter: but if I only change rows and not columns?
- OnColExit: id above.

(It would be nice if there were "OnCellEnter" and "OnCellExit" events)

Thanks
« Last Edit: September 20, 2023, 06:46:58 pm by micoudic »

luca

  • Jr. Member
  • **
  • Posts: 86
Re: DBGRID : How to trigger an action when leaving a cell?
« Reply #1 on: September 20, 2023, 11:33:03 am »
Hi,
because DBGrid is generally linked to a datasource, you can manage the OnDataChange event of the datasource.

Regards


wp

  • Hero Member
  • *****
  • Posts: 12459
Re: DBGRID : How to trigger an action when leaving a cell?
« Reply #2 on: September 20, 2023, 11:35:51 am »
Which kind of action? Leaving after editing? For this we have the OnEditingDone event; if fires when a cell is edited and another cell is selected or when the ENTER key is pressed.

Other than that, there are OnBeforeSelection and OnAfterSelection events, inherited from TCustomGrid, but kept protected in TDBGrid. You can access them by subclassing. OnBeforeSelection gets the col/row indices of the new cell, OnAfterSelection those of the left cell as parameters. But note that selection is a two-step process in TDBGrid which make book-keeping a bit complicated when the original source and destination cells are needed.

See also the attached simple project.

micoudic

  • New Member
  • *
  • Posts: 30
Re: DBGRID : How to trigger an action when leaving a cell?
« Reply #3 on: September 20, 2023, 06:45:27 pm »
Thank you for your answers.

I knew about the "OnEditingDone" event, but I didn't know how to know from which cell the event was occurring (I only do processing on certain cells)

I ended up finding the solution by searching everywhere.
It works perfectly now. Thanks again  :D

 

TinyPortal © 2005-2018