How Do I Open a Table Cell For Editing?

By default a table cell can be edited if the user double-clicks on the cell. This tutorial explains what goes on in the default column behavior so you can customize behavior if you would like.

Note: The default column behavior is stored in button "Default Column" of stack "revDataGridLibrary"

What You Need to Know

In order to edit the columns of a data grid table you need to know about the following:

1) The EditFieldText command

2) The EditValue message

3) The EditKey and EditKeyOfIndex commands

4) The CloseFieldEditor command which can be sent as a result of calling EditFieldText.

Read up on the entries for EditFieldText, EditValue, EditCell/EditCellOfIndex in the API documentation.

EditFieldText

The EditFieldText command will create an editor for a field that you specify. The default column behavior calls this command with all three parameters so that data is automatically saved after the user finishes editing.

EditValue

EditValue is the message that is sent to a row when a request to edit a fields contents has been made. The default column behavior calls EditFieldText when this message is received.

EditCell and EditCellOfIndex

There are two commands that will open a cell for editing. They are EditCell and EditCellOfIndex. Each takes the name of the column 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.

put "FirstName" into theColumn
put the dgHilitedLine of me into theLineNo
EditCell theColumn, theLineNo
put "FirstName" into theColumn
put the dgHilitedIndex of me into theIndex
EditCellOfIndex theColumn, theIndex

Either of the above calls will trigger the EditValue message.

on EditValue
	## Example of opening a field editor for the targeted column.
	## Since I'm passing in parameters 2 and 3 any changes will automatically be saved to the dgData.
	EditFieldText the long id of me, the dgIndex of me, the dgColumn of me
end EditValue

CloseFieldEditor

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.

Example of storing value in dgData in CloseFieldEditor. This would be required if you only passed in one parameter to EditFieldText.

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

6 Comments

Paul Foraker

"By default a table cell can be edited if the user double-clicks on the cell."

But, only if there is already data in the cell.

Trevor DeVore

@Paul: Actually you don't need to have data in a cell, just an existing row. If there is now row where you double-click then there is nothing to edit.

Paul Foraker

Is there a way to enable opening the cell for edit by the user when the cell is in the next (empty) row -- like the behavior you'd expect from a spreadsheet?

Trevor DeVore

@Paul: Just add a new row to the data grid (empty values in all columns) and then open the cell of the new row for editing.

Bob Sneidar

How can I detect that the user double clicked on a cell of a non existent row? I want to append enough rows to accommodate editing wherever a user clicks. Trapping for double click does it alright, except that double clicking the column header and scroll bars ALSO generates a mouseDoubleUp message. I can filter out the column header double click but not the scroll bar double click.

Trevor DeVore

@Bob: Take a look at the following two lessons. They discuss the dgHeader and dgHeaderControl custom properties. If the user did not click on an actual row (the dgDataControl property is empty) and the dgHeader is empty then the user clicked in empty space.

http://lessons.runrev.com/spaces/lessons/manuals/datagrid/lessons/8411-How-Do-I-Display-a-Contextual-Menu-When-the-User-Clicks-on-a-Column-Header-

http://lessons.runrev.com/spaces/lessons/manuals/datagrid/lessons/8410-How-Do-I-Determine-If-a-User-Clicks-In-The-Table-Header-

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.