[SOLVED] How do you unselect a powertable row without using CTRL key

Good morning,

I want to be able to select a power table row with a mouse click and then also unselect the power table row with a mouse click. (Typically you unselect a row using CTRL + mouse click on a row.) The reason for this is the user has a touchscreen and wont be able to access a CTRL key.

Thanks for any help.

The link has some information on table selection Java methods
https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#setRowSelectionInterval(int,%20int)
Your script should look something like this

target = event.source.parent.getComponent('Power Table').getTable()
selection = target.getSelectedRow()
if selection != -1:
    target.clearSelection()
2 Likes

I was able to do this by adding a custom properrty to a power table named selectedRowPrevious and then using the following script in the table’s onMousePress event.

I assume this will work on a touch screen.

	if self.selectedRowPrevious == rowIndex:
		self.selectedRow = -1
	self.selectedRowPrevious = rowIndex
2 Likes

Thank you both. Both solutions work but JGJohnson’s solution works better for my particular application.

IIRC, I think this depends on the touchscreen and its driver. Some touchscreens will emulate a mouse click where some will not.