Datagrid closefield event?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Datagrid closefield event?

Post by Zax » Wed Mar 16, 2022 2:04 pm

Hello,

I know it has already been discussed but I don't find a correct answer.
Is there is a way to trap the equivalent of "on closeField", but for a Datagrid (table) editable cell? I would like to know what row and cell has been modified.

I found:

Code: Select all

on closeFieldEditor pFEditor
   put the dgHilitedIndexes of me into numIndex
   put the dgDataOfIndex[numIndex] of me into tLine
   ...
end closeFieldEditor
But there is 2 problems:
1 - only the modified row is known, not the cell
2 - tLine (array) only contains the previous values of the DG line, not the ones after "closing" the cell.

Thank you.


@Klaus: it is the right time to answer a very simple built-in function and say "it's Livecode" ;)

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid closefield event?

Post by Klaus » Wed Mar 16, 2022 2:18 pm

Hi Zax,

well, datagrids are quite complicated beasts, so no easy built-in function! :D
This is from the Data_Grid.pdf from the LC lessons site:

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
So you could check
-> the dgcolumn of me = the column that is being updated
and
-> theDataA = the updated array of the index
at the end of that handler

Is that what you mean?


Best

Klaus

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Datagrid closefield event?

Post by Zax » Wed Mar 16, 2022 2:47 pm

Yes !!! :D
Thank you very much Klaus, even it's not an easy one-line function.

EDIT : is there a way to know the colum's name of the edited cell?
EDIT 2: "the dgColumn of me" is empty.


BTW: where is this .pdf you are talking about?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Datagrid closefield event?

Post by dunbarx » Wed Mar 16, 2022 3:10 pm

The real issue with datagrids is that when a "cell" seems to be open for editing, what you are seeing is in fact another field entirely, that overlies the cell if of interest, called in many discussions on this forum a "phantom" field. It is in that field that you edit data, and when you close out, the data in that field is loaded into a "real" field just below.

The actual fields in a DG are named something like "Col 1 0005", which is sort of self explanatory.

But the phantom field does not send "exitField" or "closeField" messages. You would have to hack the DG itself, very doable, since it is 100% built from standard LiveCode controls, but not easy.

Klaus loves to call them "beasts".

Craig
Last edited by dunbarx on Wed Mar 16, 2022 4:02 pm, edited 1 time in total.

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Datagrid closefield event?

Post by Zax » Wed Mar 16, 2022 3:21 pm

Well, I could hack the "EditValue" command from the default behavior, and set new custom properties, like this:

Code: Select all

command EditValue
   EditFieldText the long ID of me, the dgIndex of me, the dgColumn of me
   set the MT_editIndex of the dgControl of me to the dgIndex of me
   set the MT_editColName of the dgControl of me to the dgColumn of me
end EditValue
But it seems rather complicated, and maybe not very safe. So I would prefer Klaus' way... if only I could retrieve the column's name.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Datagrid closefield event?

Post by dunbarx » Wed Mar 16, 2022 4:09 pm

If it is of any help to you, that delicate ephemeral field that the DG builds on the fly is named "dataGridFieldEditor". It is hard to catch.

Craig

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid closefield event?

Post by Klaus » Wed Mar 16, 2022 4:45 pm

Hi Zax,

sorry, looks like the code snippt will only work if you also evoked the FieldEditor yourself via script.
And unfortunately, the DataGrid PDF is not avaialable anymore on the LC website.
I put it in my Dropbox:
https://www.dropbox.com/s/8fkuzeipk48q8 ... f.zip?dl=1

I am currently looking into the 15.000 lines of the datagrid library to find a hint on the column clicked.
Will report here if I am successful... :D


Best

Klaus

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Datagrid closefield event?

Post by Zax » Wed Mar 16, 2022 4:53 pm

Thanks for the upload Klaus :)

I will also look at the pdf. I suggest to both report here, even if we are not successful.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid closefield event?

Post by Klaus » Wed Mar 16, 2022 4:58 pm

Success! :-)

Put this into the script of the datagrid group and see what the messagebox shows:

Code: Select all

command EditFieldText pField, pIndex, pKey
   put "Index:" && pIndex & CR & "Columnname:" && pKey
   
   ## Most important line:
   pass EditFieldText
end EditFieldText
Tested and works!

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Datagrid closefield event?

Post by Zax » Thu Mar 17, 2022 6:54 am

Thank you so much for your time Klaus :)

I tested your script. It's an "openField" script that does the same thing that the one I posted earlier:

Code: Select all

command EditValue
   EditFieldText the long ID of me, the dgIndex of me, the dgColumn of me
   set the MT_editIndex of the dgControl of me to the dgIndex of me
   set the MT_editColName of the dgControl of me to the dgColumn of me
   ---- testing
   put "Index:" && the dgIndex of me & CR & "Columnname:" && the dgColumn of me 
end EditValue
However, yours is more convenient because it can be placed in the DG grid script itselft, and not in a deep and mysterious template.

But I have to say that an "openField" script is not exactly what I am looking for because I need to perform action on "closeField" (when cell data has been modified).
As far as I can see, the problem is the dgColumn: I don't understand when it can be accessed or not.

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Datagrid closefield event?

Post by Zax » Thu Mar 17, 2022 7:23 am

OK, I finally found it :)

This script must be placed in the default column behavior, following this lesson:
https://lessons.livecode.com/m/datagrid ... -to-a-cell

Code: Select all

on CloseFieldEditor pFieldEditor
   put the dgIndex of me into tIndex
   put the dgColumn of me into colName
   put the text of pFieldEditor into newCellData
   put "tIndex=" & tIndex & "---colName=" & colName & "---newCellData=" & newCellData
end CloseFieldEditor

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid closefield event?

Post by Klaus » Thu Mar 17, 2022 10:17 am

Glad you conquered your complicated beast! :-D

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Datagrid closefield event?

Post by stam » Thu Mar 17, 2022 4:05 pm


Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Datagrid closefield event?

Post by Zax » Thu Mar 17, 2022 4:15 pm

Thanks for the link.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”