LiveCode LessonsLiveCode Data Grid Using The Built-In Field EditorHow Can The User Edit Field Content in a Data Grid Form?

How Can The User Edit Field Content in a Data Grid Form?

The data grid commands for creating an editor for a particular field in a row template. This lesson will show you how to use them.

What You Need to Know

In order to edit field contents in a data grid form you need to know about the following:

1) The EditFieldText command

2) The EditValue message

3) The EditKey and EditKeyOfIndex commands

Read up on the entries for EditFieldText, EditValue and EditKey/EditKeyOfIndex in the API documentation.


The EditFieldText command will create an editor for a field that you specify. You can use this command to create a field editor for a field in your row template.


EditValue is the message that is sent to a row when a request to edit a fields contents has been made. You can call EditFieldText from within this message to begin an editing operation.

EditKey and EditKeyOfIndex

EditKey and EditKeyOfIndex will trigger the EditValue message in a row. Each takes the name of the key you want to edit and the line or index you want to edit. Here are two example scripts showing how you could use these commands in the script of a data grid.

## Placed in script of row template behavior
on mouseDown pBtnNum
	if pBtnNum is 1 then
		## Did the user click on the FirstName field?
		if the short name of the target is "FirstName" then
			put "FirstName" into theKey
			put the dgHilitedLine of me into theLineNo
			EditKey theKey, theLineNo
		end if
	end if
end mouseDown
on mouseDown pBtnNum
	if pBtnNum is 1 then
		## Did the user click on the FirstName field?
		if the short name of the target is "FirstName" then
			put "FirstName" into theKey
			put the dgHilitedIndex of me into theIndex
			EditKeyOfIndex theKey, theIndex
		end if
	end if
end mouseDown

Either of the above calls will trigger the EditValue message. The EditValue can be thought of as a central message where you can open a field for editing text. This message is where you will call EditFieldText.

on EditValue pKey
	## Example of opening a field editor for the field displaying the value for pKey
	## Since I'm passing in parameters 2 and 3 any changes will automatically be saved to the dgData.
	## 'me' is the Data Grid in this case.
	EditFieldText the long id of field pKey of me, the dgHilitedIndex of me, pKey
end EditValue


If the user changes any content in the field editor this message will be sent to the field targeted in the first parameter sent to EditFieldText. Read the API docs for EditFieldText which discusses this message.

Here is an example of storing the new value in the dgData of the Data Grid in the CloseFieldEditor handler. Manually storing the value would be required if you only passed in one parameter to EditFieldText.

This example script would be in the Row Behavior script as it uses the dgIndex of me property.

on CloseFieldEditor pFieldEditor
	## 'me' is the row control
	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


Michel F. Lukawecki


Totally lost, here.

I created a test datagrid form. Put some data into it. Without any special "programming", I can double-click on a line and edit it!

What's the point of using the procedure described in this lesson???


Elanor Buchanan

Hi Michel,

This procedure is for if you have created a custom row template for your Data Grid from or if you want to change the default behavior for editing field content. If you have a look at the script for the row in a new Data Grid form you will see that there is a mouseDoubleUp handler which checks the target and calls EditFieldText. If you want to add more fields or modify how a user chooses to edit a field you would follow this lesson.

If the default behavior provides what you need then you don't need to make any changes to the script.

I hope that helps.

Kind regards


Add your comment

E-Mail me when someone replies to this comment