Page 1 of 1
Datagrid closefield on text field - line number and data
Posted: Tue Aug 11, 2015 6:58 am
by bergsy
Hi,
I have a datagrid that has a number of objects in each line. One of them is a text field. When the user edits the field and then exits (eg. on line 2), I want to know the line number of the text field in the datagrid so that I can interrogate the other values in the line.
I have tried the code below with no success - I get no linenumber with any of these and thus can't get the data of the line
on closeField
put the dgHilitedLines of group "dgQuestions" into theLine
put the dgIndex of me into theLine2
put the dgRow of me into theLine3
put the dgHilitedLines of the target into theLine4
put the dgDataOfLine[theLine] of the target into theRowData
put updateResponse(theLine, theLine2, theLine3, theLine4, the text of me, theRowData) into bOK
end closeField
when I set a breakpoint in updateResponse all the line variables are empty.
I suppose I could search the whole datagrid for "the text of me" but that seems like overkill.
Thanks
Greg
Re: Datagrid closefield on text field - line number and data
Posted: Tue Aug 11, 2015 2:42 pm
by sritcp
Hi Greg:
1. Datagrids are quite complex under the hood. We need to know the message as well as the recipient of the message in order to mess with them. For example, when we edit a field in a datagrid table,
EditCell or
EditCellOfIndex is sent to the datagrid; in turn,
EditValue is sent to the column control; in turn,
EditFieldText is sent to the field. This is followed by
preOpenFieldEditor,
deleteFieldEditor, and
closeFieldEditor !!! In other words, I avoid opening the hood of a datagrid if I can help it!
2. The "index" is a permanent identifier of a row of records. "Line" is temporary and can change with sorting, for example. It is best to use dgDataOfIndex unless you have specific reasons for using line numbers.
3. What is "dgRow"? I don't see such a property in the datagrid manual.
4. Put the following code into the script of the datagrid:
Code: Select all
on closeFieldEditor pFEditor
put the dgHilitedIndex of me into the cLastEditedIndex of me
end closeFieldEditor
You can then use this custom property "cLastEditedIndex" to obtain the row data:
Code: Select all
put the dgDataOfIndex[the cLastEditedIndex of me] into tArray
Regards,
Sri
EDIT: Sorry, my examples refer to a datagrid table; you seem to imply a datagrid form. Either way, try the code, it should work.
Re: Datagrid closefield on text field - line number and data
Posted: Wed Aug 12, 2015 11:20 pm
by bergsy
Hi Sri,
I have a form, not a table.
I put the code in the behaviour script. The code didn't compile as it would not allow me to create an attribute "cLastEditedIndex of me". So I put it into a variable to try to run the code. However the closeFieldEditor function is never called (I set a breakpoint that was never hit)
I tried setting up a closeField/exitField function but still get an empty index
Not sure what to do next
Greg
Re: Datagrid closefield on text field - line number and data
Posted: Thu Aug 13, 2015 4:33 am
by sritcp
Hi Greg:
Mea culpa.
You have to "set" a property, not "put" a value into it.
Code: Select all
on closeFieldEditor pFEditor
set the cLastEditedIndex of me to the dgHilitedIndex of me
end closeFieldEditor
This works with Datagrid table.
I'll try it out on a datagrid form when I have some time tomorrow.
Regards,
Sri
Re: Datagrid closefield on text field - line number and data
Posted: Thu Aug 13, 2015 4:50 am
by bergsy
Thanks Sri
That still doesn't resolve the fact that I don't even get to the function - probably a difference between tables and forms
I'll keep poking around too
Cheers
Greg
Re: Datagrid closefield on text field - line number and data
Posted: Thu Aug 13, 2015 4:14 pm
by sritcp
This works for me with a Datagrid Form: put the following in the datagrid script
Code: Select all
on closeField
set the cLastEditedIndex of me to the dgIndex of the dgDataControl of the target
put "The index of the last edited field is: " & the cLastEditedIndex of me into msg
end closeField
Let me know if this works for you.
Regards,
Sri
Re: Datagrid closefield on text field - line number and data
Posted: Thu Sep 17, 2015 5:24 am
by bergsy
Hi Sri,
Sorry for the delay. I have been taken away for developing funding pitches for potential investors
I should get back to this within the next week or so
Cheers
Greg