Page 1 of 1

Datagrid - Detecting Return in Field

Posted: Fri Jan 02, 2015 11:37 pm
by Simon Knight
Hi,

I would like my code to react to the return key being pressed in one of the two fields on my datagrid form. I have trapped the key press in both a custom field editor script and the script of the datagrid group but I am unable to determine which field is being edited.

Code: Select all

on returnInField
   put the short name of the target into theField
   put "Return in Field reports that the field name is " & theField & Cr after fld "debug"
    if the autotab of me then
        send "DeleteFieldEditor" to the dgControl of me in 0 seconds
    else
        pass returnInField
    end if
end returnInField
This code just populates the variable thefield with the name of the field editor. Is there a way of getting the name of the field on the datagrid ?

Simon K

Re: Datagrid - Detecting Return in Field

Posted: Sat Jan 03, 2015 4:10 am
by dunbarx
Hi.

I only use DG table styles. If I place a handler in the group script like:

Code: Select all

on mouseUp
   put the short name of the target into fld 1
end mouseUp
I get the usual: "col 2 0001", or whatever. When you say you get the "field editor", do you mean the "ghost" field that the object creates on the fly, that is, the editable field for data entry?

Craig Newman

Re: Datagrid - Detecting Return in Field

Posted: Sat Jan 03, 2015 9:56 am
by Simon Knight
Hi Craig,

Yes, depending on where I put the code I can get either the name of the field but no detection of keydown or I get the keydown but the field is reported as the ghost fieldeditor field.

I am trying to emulate an outline app where in return in the title adds a new row/record and a return in the note field adds a return in the note text.

Simon K.

Re: Datagrid - Detecting Return in Field

Posted: Sat Jan 03, 2015 9:14 pm
by sritcp
Hi Simon:

May I ask where you put the code to detect the keyDown, and where to get the name of the field?

I wonder if you can save the name of the current field in a global (which is updated on closeField, say), and use it with the key information gleaned separately.

Regards,
Sri.

Re: Datagrid - Detecting Return in Field

Posted: Sun Jan 04, 2015 6:11 pm
by Simon Knight
The code snip was in a button behavior used as the CustomFieldEditor. I have tried of the target and of me and both return the field name as "DataGridFieldEditor".

Re: Datagrid - Detecting Return in Field

Posted: Sun Jan 04, 2015 6:28 pm
by Simon Knight
I wonder if you can save the name of the current field in a global (which is updated on closeField, say), and use it with the key information gleaned separately.
Thanks it works : I added a custom property to the datagrid group and populate it with the name of the field in the row behavior handler EditValue pKey which is called when the field is selected.

Many thanks,

Simon K