* * *

Author Topic: TDrawGrid selection  (Read 529 times)

mtanner

  • Full Member
  • ***
  • Posts: 204
TDrawGrid selection
« on: August 30, 2017, 10:51:43 am »
In my app I have a TDrawGrid, and some separate radio buttons for some options.

I can select a cell in the frig, enter data, retrieve it and update the apps data structures, using OnSetEditText, and processing the new values in OnEditingDone.

My problem is that having edited a cell I cannot then just click one of the radio buttons. If I do that then OnEditingDone for the grid gets called. I have to tab out of the grid, to make it no longer the active control, before I can use the radio buttons.

How can I the get the grid out of whatever mode it is in so I can access other controls on the form, without having to tab away from the grid (not very user-friendly having to do that).

I have discovered that I can get the behaviour I want simply by not using OnEditingDone. Since OnEditingDone seems a useful event, my question still stands, and I any guidance on using OnEditingDone would be helpful.

howardpc

  • Hero Member
  • *****
  • Posts: 2396
Re: TDrawGrid selection
« Reply #1 on: August 30, 2017, 04:29:17 pm »
OnEditingDone is simply behaving as its name would lead you to expect.

If the processing you have put in that event is getting called more than once inappropriately (i.e. more often than you want) you can set OnEditingDone to Nil in some other suitable event (such as MouseLeave) and set it back to its original value in some other appropriate event (such as MouseEnter).

However, resorting to techniques like this usually means your program logic and event use is not thought out well. TDrawGrid has a particularly rich set of events to choose from, and you might need to rethink which ones you are using, or ignoring, and why.

wp

  • Hero Member
  • *****
  • Posts: 3893
Re: TDrawGrid selection
« Reply #2 on: August 30, 2017, 05:10:21 pm »
Are the radiobuttons children of the grid?

Please post a little project to demonstrate the issue.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

mtanner

  • Full Member
  • ***
  • Posts: 204
Re: TDrawGrid selection
« Reply #3 on: August 30, 2017, 06:01:29 pm »
It's not that the post-edit processing is getting done more than once, it is that OnEditingDone is invoked by and user interacytion with the form containihg the TDrawGrid. Unless I tab out of the TDrawGrid, any attempt to click on another control on the form just results in OnEditingDone being invoked again.
 
If I just do my post-edit app processing in OnSetEditText, then I can click on another control on the form ok.

What actually trigers OnEditingDone. If I am typing a number into the selected cell, each character is processed by OnSetEditText (which means doing the app calculations at each character input, which does not cause me any problems with my app. How does  TDrawGrid know when I have finished typing in more digits?

Just to be clear, the controls, radio buttons, I refer to are not connected to the TDrawGrid in any way, except for being on the same form.

howardpc

  • Hero Member
  • *****
  • Posts: 2396
Re: TDrawGrid selection
« Reply #4 on: August 30, 2017, 06:56:09 pm »
OnEditingDone is triggered when you leave a TWinControl with an active editor.
So the change of focus from edited-grid-cell to radiobutton is bound to invoke the grid's OnEditingDone. This is precisely the moment about which the event was designed to notify you.
TDrawGrid does not know that you have finished typing per se. It knows only that the user has moved the focus elsewhere, (and hence it will no longer receive keystrokes).

wp

  • Hero Member
  • *****
  • Posts: 3893
Re: TDrawGrid selection
« Reply #5 on: August 30, 2017, 07:21:26 pm »
I still don't understand what you want to achieve? Do you want to keep the cell editor active while you tab out of the grid to the radiobuttons? This will not work. OnEditing done is invoked whenever the grid loses focus, or another cell is selected, or when ENTER is pressed. These actions clearly indicate that editing is "done".

Which code do you execute in OnEditingDone?
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

mtanner

  • Full Member
  • ***
  • Posts: 204
Re: TDrawGrid selection
« Reply #6 on: August 31, 2017, 12:00:10 am »
It makes sense to me now - OnEditingDone being triggered when all editing of the grid is finished, when focus is moved out of the grid. I was thinking it might be when editing of a particular cell is finished. 

So I should not be using OnEditingDone.

Thanks for the help.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus