Right now, if a cell has a value, I can edit that value, but I can not delete it. The table turns the cell red and I can’t move on until entering something in the cell.
Any Ideas?
My end goal is to have NULL stored in the database, and nothing appear in the table cell.
Stuart,
I had the exact same issue. The only way I could get around it was to put a “Clear Cell” function in a right-click popup menu.
My code is below, in case it helps you. Note that I only wanted to fire this option on columns 3-8 inclusive. I had to define my database column names because my table headers were different. I am sure there’s a more efficient way, but it does work. All of the java stuff was to select the table cell when I right click (note that my header is two rows high so I am subtracting 32 points from the Y coordinate to account for that).
As with any popup menu, put the code in MousePressed and MouseReleased.
Any questions, let me know.
Cas
if event.button != event.BUTTON1:
def clearCell(event):
id = event.source.data.getValueAt(event.source.selectedRow,"ID")
colIndex = event.source.selectedColumn
if colIndex == 3:
dbfield = 'WTMin'
elif colIndex == 4:
dbfield = 'WTMax'
elif colIndex == 5:
dbfield = 'OOR'
elif colIndex == 6:
dbfield = 'OD'
elif colIndex == 7:
dbfield = 'SmpTime'
elif colIndex == 8:
dbfield = 'BoxQC'
if system.gui.confirm("Are you sure you want to clear this cell?","Clear Cell?"):
query = "UPDATE ShiftQC SET %s = NULL WHERE id = ?" % (dbfield)
args = [id]
system.db.runPrepUpdate(query, args)
system.db.refresh(event.source,"data")
if event.popupTrigger:
#These seven lines select the correct row in the table.
from java.awt import Point
tbl = event.source
jTbl = tbl.getTable()
newY = jTbl.getVisibleRect().y
newX = jTbl.getVisibleRect().x
oldPoint = event.getPoint()
newPoint = Point(oldPoint.x + newX, oldPoint.y-32)
tbl.setSelectedRow(jTbl.rowAtPoint(newPoint))
tbl.setSelectedColumn(jTbl.columnAtPoint(newPoint))
selCol = event.source.selectedColumn
selRow = event.source.selectedRow
ID = event.source.data.getValueAt(event.source.selectedRow,"ID")
if selCol in range(3,9):
names = ["Clear this Cell"]
functions = [clearCell]
menu = system.gui.createPopupMenu(names, functions)
menu.show(event)