So far I have not been able to get @justinedwards.jle suggestion to work and I'm trying to avoid the reflection that @pturmel mentions because I know nothing about reflection and I would like to avoid that advanced method if possible.
I have the mentioned settings on the table set correctly.
but I should mention that column selection is allowed I have tried both column selection allowed and disallowed and that some of the columns are editable.
I tacked this code onto the end of what I had for troubleshooting purposes - vrws is the list of originally selected valid rows.
print "vrws: {}".format(vrws)
table = event.source.parent.getComponent('ptLengths').table
print "Selecting row: {}".format(vrws[0])
table.setRowSelectionInterval(vrws[0], vrws[0])
for i in range(1,len(vrws)):
print "Selecting row: {}".format(vrws[i])
table.addRowSelectionInterval(vrws[i],vrws[i])
nwrws = pt.getSelectedRows()
print "nwrws: {}".format(nwrws)
The code acts like it works, but in the end nothing in the table is selected and nwrws is empty. This is the output to the console:
vrws: [1, 2, 3, 4, 5, 6, 7]
Selecting row: 1
Selecting row: 2
Selecting row: 3
Selecting row: 4
Selecting row: 5
Selecting row: 6
Selecting row: 7
nwrws: array('i')
I also looked at the post Programmatically Set Selected Cell in Power Table that @dkhayes117 mentions, and there may be some hope there with table.changeSelection()
, but at the moment I'm trying to figure out how to make that work with a non-contiguous selection.
In the end, I had to use table.changeSelection()
, and to make it work I had to use the toggle and extend flags differently than what seemed obvious to me. My confusion came from the fact that the extend flag changes what it does based on the toggle flag. When both flags are false, table.changeSelection()
, clears the previous selection, and starts a new selection, but if toggle is true and extend is false, the previous selection is not cleared and the selection state of the cell referred to is simply toggled. That allowed the following code to work (I had to assume that nothing was selected after the aforementioned table changes).
print "val_rws: {}".format(val_rws)
table = event.source.parent.getComponent('ptLengths').table
print "Selecting row: {}".format(val_rws[0])
table.changeSelection(val_rws[0], 0,0,0)
for i in range(1,len(val_rws)):
print "Selecting row: {}".format(val_rws[i])
table.changeSelection(val_rws[i],0,1,0)
nwrws = pt.getSelectedRows()
print "nwrws: {}".format(nwrws)