How to test whether a data grid field editor is open?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
MichaelBluejay
Posts: 234
Joined: Thu Jul 01, 2010 11:50 am

How to test whether a data grid field editor is open?

Post by MichaelBluejay » Thu Oct 24, 2019 10:05 pm

I scripted my Data Grid to delete the selected row when the user presses the Backspace key. That has the unintended effect of deleting a row even if the user has opened a cell for editing. So, how can I check whether a cell is open for editing?

I thought I could set a "notOkayToDelete" flag in the on preOpenFieldEditor handler, but I don't know how to check for the editor closing so I can clear that flag. closeFieldEditor is sent only if the field contents have changed, and there seems to be no message sent if the editor is closed with no changes.
Last edited by MichaelBluejay on Fri Oct 25, 2019 5:02 am, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: How to test whether a data grid field editor is open?

Post by dunbarx » Fri Oct 25, 2019 3:07 am

Michael.

Fields in DG's do not open for editing. A separate "phantom" field is made visible, and sized and placed over the field of interest. So the topLeftMost field is named "Col 1 0001", but it is that other field that you see with the blinking cursor.

Trevor DeVore created the dataGrid. He is on this forum. Perhaps he might have some insight.

Trevore?

Craig

MichaelBluejay
Posts: 234
Joined: Thu Jul 01, 2010 11:50 am

Re: How to test whether a data grid field editor is open?

Post by MichaelBluejay » Fri Oct 25, 2019 5:01 am

Aha! That'll work:

Code: Select all

on backspaceKey
   if the short name of focusedObject() is "DataGridFieldEditor" then pass backspaceKey
   else [delete the line]
end backspaceKey
Thanks, Craig.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: How to test whether a data grid field editor is open?

Post by dunbarx » Fri Oct 25, 2019 2:06 pm

Michael.

I knew it would be fun to have you around :wink:

And I never knew until now that the "phantom" field was created for each instance of use, not merely socked away and shown. I did it this way, clicking and then typing in a cell in a tiny DG:

Code: Select all

on rawKeyDown
   repeat with y = 1 to the number of flds
      put the name of fld y into line y of fieldList
   end repeat
   breakPoint
end rawKeyDown
If you click outside a "cell" that contains data, there is no phantom. If inside, you see it. How did you do it?
Craig

EDIT:

It occurred to me that an easy way to test that theory would be to search for the word "create" in the DG. There is no such command. :shock:

MichaelBluejay
Posts: 234
Joined: Thu Jul 01, 2010 11:50 am

Re: How to test whether a data grid field editor is open?

Post by MichaelBluejay » Fri Oct 25, 2019 8:27 pm

Code: Select all

on idle
   put the name of the focusedObject
end idle
Heh.

Post Reply