Run Update Query after Table Cell Edited

After editing a cell in a table I would like to run an update query to throw then new value into my database. How do I get the query to run on the enter key?

I’ve done the following but for some reason it doesn’t see this as being true:

if event.keyCode == event.VK_ENTER:
print “Enter Key”
databaseTable = “[shredder].[dbo].[Shredder_Grate_Tracking]”
tableData =
rowIndex = event.source.selectedRow
colIndex = event.source.selectedColumn
columnName = tableData.getColumnName(colIndex)
id = tableData.getValueAt(rowIndex, “ID”)
vendor = tableData.getValueAt(rowIndex, “Manufacturer”)
rowDate = tableData.getValueAt(rowIndex, “Date Installed”)
value = tableData.getValueAt(rowIndex, colIndex)

if columnName == "Cost":
	query = "UPDATE [shredder].[dbo].[Shredder_Grate_Tracking] SET COST = '%f' WHERE ID = '%i' AND VENDOR = '%s'" %(value, id, vendor)

I figured it out, I put this event on the keyPressed which didn’t work so I used the keyReleased and it works good.

There is an event handler for the table component called cellEdited, you don’t have to worry about trying to capture that event yourself.

You can use event.row and event.column to get both the primary key, and the table column where the value will be updated. You can then run a prepUpdate to get the new value in the database:

columnName = primaryKeyValue =, "id") query = "UPDATE some_table SET %s=? WHERE id=?" % columnName system.db.runPrepUpdate(query, [event.newValue, primaryKeyValue])

EDIT: I see you figured out a different way, nice job.

1 Like

Oh ya, I like the cellEdit better, I found that VK_TAB didn’t work with either keyPressed or keyRelease. Thanks