Forum Archive

How to select all items in a table view? (iOS python ui on Pythonista)

BobPeltonUK

I tried really everything but no success,also tried to look for it in here and google but Nothing !

Cycling all items and append them in the selected rows list has no effect!
Thanks in advance.

BobPeltonUK

Here’s the def:

def SelezionaTutti(sender): chkbox=sender.superview['SwitchSelezionaTutti'] listview=sender.superview['DatiDaExcel'] if chkbox.value==True: for i in listview.data_source.items: listview.selected_rows.append(i) elif chkbox.value==False: listview.selectedindex=-1 print(listview.selected_rows)

brumm

TableView.selected_rows needs a sequence of selected rows, each as a 2-tuple (section, row). try (0, row)

BobPeltonUK

Where do I put the tuple? It’s ok to iterate on datasource.items to select them?

brumm
length = len(self.view['tableview1'].data_source.items)
r = []
for i in range(1, length):
    t = tuple([0, i])
    r.append(t)
    self.view['tableview1'].selected_rows = r
BobPeltonUK

Perfect IT WORKS!!
now the problem is how to deselect all :D but i can get to it!

Gcarver

I was having an issue setting TableView.selected_rows. I discovered that my problem was assignment doesn't replace the current list, but adds to it. So setting it to [] will not clear the current selections and adding say [(0, 1)] will simply add row 1 to the already selected rows.
The only way I could find to clear the current selections to [] was calling TableView.reload_data() before setting selected_rows.

JonB

Have you tried using append and clear or del, rather than setting to a new empty list?

I.e
tableview.selected_rows.append((0,1))

And either

tableview.selected_rows.clear()

Or
del tableview.selected_rows[:]

To clear it.

I can imagine a scenario where the selected_rows object is linked in some way to the native iOS list, and so just setting to a new object doesn't actually clear the old one..