Hey there everyone,
I’m trying to create a table cell where I can select from existing similar values in a dropdown, or type new values into it like a regular table cell or text box… the following code on my PowerTable gets me very close…
def configureEditor(self, colIndex, colName):
if colName == 'SubProject':
ProjectID = self.parent.ProjectID
from javax.swing import AbstractCellEditor, JComboBox
from javax.swing.table import TableCellEditor
class MyCellEditor(TableCellEditor, AbstractCellEditor):
def __init__(self, tableComponent):
self.table = tableComponent
self.cbValues = None
def getTableCellEditorComponent(self, table, value, isSelected, rowIndex, vColIndex):
# Get a list of other values existing values
newData = system.db.runPrepQuery("SELECT DISTINCT C.[SubProject] FROM OMS.[Categories] AS C INNER JOIN CRM.[Milestones] AS M ON M.[ID] = C.[MilestoneID] WHERE M.[ProjectID] = ? ORDER BY C.[SubProject]", [ProjectID])
newList = []
for row in newData:
newList.append(row[colName])
# Build the Combo box with the values from above
self.cbValues = JComboBox(newList)
# Make the combo box editable
self.cbValues.setEditable(1)
# Ensure that the existing value is selected.
self.cbValues.setSelectedItem(value)
return self.cbValues
def getCellEditorValue(self):
return self.cbValues.getSelectedItem()
return {'editor': MyCellEditor(self)}
The only drawback is that after I type a new value into it and press enter, it doesn’t stop editing and lose focus… I have to know to click on something else on the screen in order for the value I entered to “stick” by calling the powertable’s onCellEdited event.
Does anyone know how to make the typed editing behave more like a regular text box, where pressing enter commits the edit? Thanks in advance!
Frank.