Page 1 of 1

Last edited field in a datagrid

Posted: Sat Sep 26, 2015 8:17 pm
by lohill
In a table datagrid where editing is allowed, the user can change the data in the columns. It is not until they tab to the next field that the data is officially registered in the previous field as far as I can tell. As a result, if the user forgets to tab out of the last edited cell when they quit editing the grid, that last field does not actually get entered. Is there some command that can be given to a datagrid when moving on that will make sure all cells have their data registered even though the last one was not tabbed from.

Thanks,
Larry

Re: Last edited field in a datagrid

Posted: Sun Sep 27, 2015 4:21 am
by dunbarx
Hi.

I am not sure what you are seeing. In a DG, if you edit a field, and then, say, click on the card window, or perhaps immediately navigate to another card with( cmd-3) and then back again, the field contents remain as you last left them..

You can always:

Code: Select all

dispatch "RefreshList" to group "yourDataGrid"
But what scenario are you seeing?

Craig Newman

Re: Last edited field in a datagrid

Posted: Mon Sep 28, 2015 5:15 pm
by lohill
Hi Craig,

Dispatching "RefreshList" doesn't seem to accomplish what I want. My dataGrid is in a modal dialog window (not the most conducive environment for debugging) where the user can be presented with multiple datagrid rows where each one can be edited. If the user fails to tab out of the last cell they edit prior to pressing the OK button, the last piece of data is not really in the grid and consequentially is that in the array that gets put into dialogData to be returned to the card that initiated the dialog. What I need is a come command to put at the beginning of the OK script the will tell the grid to "close'" and accept that last bit of information.

Thanks,
Larry

Re: Last edited field in a datagrid

Posted: Mon Sep 28, 2015 5:53 pm
by dunbarx
Hmmm.

There are a lot of messages sent when you type into a field, and a DG is no different. Could you use the "RawKeyDown" or "selectionChanged" message to refresh the DG at each keystroke, essentially saving like HC did? There would be no noticeable delay in such a simple process.

Craig

Re: Last edited field in a datagrid

Posted: Mon Sep 28, 2015 8:50 pm
by sritcp
Hi Larry:

You will find, on p. 185-187 of the Data grid documentation, an example of manually storing the value of what is entered in a field.
This is done by handling the closeFieldEditor message. The following is reproduced from the doc:

Code: Select all

on CloseFieldEditor pFieldEditor
put the dgIndex of me into theIndex
put the dgDataOfIndex[theIndex] of the dgControl of me into theDataA put the text of pFieldEditor into theDataA[the dgColumn of me]
set the dgDataOfIndex[theIndex] of the dgControl of me to theDataA
end CloseFieldEditor
Here, pFieldEditor refers the field that was just edited.
This message is sent to the field itself (in case of table; in case of form, it is sent to the row template).

In order to use the above in your case, you need to capture the identity of the last-clicked field. You can do this by handling the mouseUp message for the data grid and storing the name of the target in a custom property, say, cLastClickedCell.

Note: in the above code, "me" refers to the field, since the message is sent to the field. If you want to handle it at the level of the data grid, you will have to modify it (and use "the cLastClickedCell of me").

Regards,
Sri.

Re: Last edited field in a datagrid

Posted: Wed Sep 30, 2015 2:02 pm
by lohill
Thanks you guys,

I'll see what I can piece together from all this.
Sri - Is that the Blue Mango document to which you refer?

Larry

Re: Last edited field in a datagrid

Posted: Wed Sep 30, 2015 3:44 pm
by lohill
Hi Sri,

I have the code you provided in the script of the datagrid and am stepping through it. If I do not edit any of the cells but just tab from one to the next, that code never gets executed as expected. If I edit a field and then tab out the code does get executed. It actually goes through that code two times but in neither case do the variables theIndex or theDataA take on any value. That does not make any sense to me. Can you think of anything I might be doing wrong? As an aside I found your code on page 158 of the Blue Mango document.

As another aside I think the following code is going to be better than your 'mouseUp' method for getting cLastClickedCell if I can get past my other problems. It will reside in the DG script.

Code: Select all

on preOpenFieldEditor
   put the long name of the target into tTarget
   set the cLastClickedCell of me to tTarget
end preOpenFieldEditor
Regards and thanks,
Larry

Re: Last edited field in a datagrid

Posted: Thu Oct 01, 2015 4:06 pm
by sritcp
Hi Larry:
lohill wrote:Sri - Is that the Blue Mango document to which you refer?
I don't know if it is the Blue Mango document, the name of the file is LiveCode_Data_Grid.pdf
On page 185-186 (out of 230 pages), is a sub-section titled "How Do I Open a Table Cell For Editing?". This section is very relevant for what you are doing.
lohill wrote:If I do not edit any of the cells but just tab from one to the next, that code never gets executed as expected.
When no editing is done, the message sent is "exitField", not "closeField"
lohill wrote:It actually goes through that code two times but in neither case do the variables theIndex or theDataA take on any value.
As I mentioned in my earlier post, closeFieldEditor is sent to the actual field being edited (in case of DG table). Where did you put the code? If you put the code in the DG script, then "me" is the DG itself, "the target" would refer to the field clicked on. Similarly, "the DgControl of me" would translate simply to "me" !! Did you modify the code?
Also, you have set the cLastClickedCell to empty after handling it. This may be why it is running twice.

Lastly, how are you triggering the "closeFieldEditor" handler? Your original problem arises from the fact that the prompt to save the edited field is not being triggered when it is not tabbed out of. So you will have to manually send the closeFieldEditor message under appropriate conditions, e.g., closeCard, focusOut, etc.

Regards,
Sri

P.S.: Yes, preOpenFieldEditor is a better choice than mouseUp