Author Topic: Palette controls event handling problem  (Read 2146 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Palette controls event handling problem
« on: September 08, 2018, 06:15:53 PM »
I have a palette, like every other palette, doesn't fire a lostFocus event.

Actually, what happens is I am hosting several controls on the palette and when the palette is no longer focused, the control that had focus on the palette maintains focus and the event tied to the control that should be firing never does …

The immediate problem is a DataGridView that has editable values that should immediately force an update of the associated object in the drawing when the item is no longer being edited.


The following events have been added to the datagrid, CellEndEdit, EditingControlShowing and (Column)KeyPress and are firing as they should with the exception of CellEndEdit. It does not fire unless a different control is selected in the palette before closing the palette or going on to do other things.

I'd appreciate any insight into how to resolve this issue.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Palette controls event handling problem
« Reply #1 on: September 08, 2018, 10:50:19 PM »
ApplicationServices.PreTranslateMessage or System.Messaging.MessageQueue?
Maybe look for a message WM_SETFOCUS, where the handle is not your palette?
Or WM_ACTIVATE /WA_INACTIVE,
Or onMouseLeave


Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Palette controls event handling problem
« Reply #2 on: September 13, 2018, 11:07:07 PM »
I think I have resolved the issue, although nothing seemed to work because the events don't work quite right in a Palette.


First, I changed the location at which I updated the drawing. Instead of doing it in EndCellEdit I created another function to update the drawing with the changed value and eliminated the EndCellEdit event.

I implemented the EditingControlShowing event and added KeyPress, PreviewKeyDown and LostFocus to the edit control

In the PreviewKeyDown event I filtered for the enter key. If the user presses the enter key, then call the function to update the drawing (all edits on that field are done).

In the KeyPress event I filtered all values that were not valid for numeric input, this solves having to parse the data after it has been entered.

In the LostFocus event for the textbox, I format the value in the textbox (at this point the edit textbox is still active) and manually call PreviewKeyDown passing the Enter key (this event DOES fire).

So, the user edits a value in the grid, if the move the mouse off the palette, the TextBox loses focus it calls the PreviewKeyDown with enter key, that submits enter, fires the function to update the drawing and all is right with the world.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Palette controls event handling problem
« Reply #3 on: September 17, 2018, 07:38:13 AM »
Glad you got something working, I played with ApplicationServices.PreTranslateMessage, created a mess of p/invokes and gave up lol