Forum Archive

Names of selected rows instead of numbers

techteej

Is there any way to get names of selected rows in a table view instead of just 0, 1, 2, etc.?

ccc
sender.items[sender.selected_row]
techteej

This gives me a list index out of range

ccc
print(sender, sender.selected_row, sender.items)
techteej

@ccc Thanks, but is there a way to display the title? Trying to get the editor to open when a row is selected. The data is from a directory.

[deleted]

@techteej You might find it helpful to look at...

'Classes' - Menu

It does many of the same things.

techteej

@tony Can't really tell what that does, sorry. You can see here what I'm trying to accomplish.

[deleted]

-

[deleted]

@techteej The line that might interest you the most is...

self.sRow = sender.tableview.data_source.items[sender.tableview.selected_row[1]]['title']
techteej

@tony I get the error NoneType has no attribute data_source

[deleted]

@techteej You've a working example in the Menu class that you can check your coding against if you like.

[deleted]

@techteej You can simplify my line so that it's like @ccc's above (Menu was one of the first things I wrote and I've gone up in order to come back down again to where I was, but there were no examples to follow that I could find when I started)

self.sRow = sender.items[sender.selected_row]['title']

It's telling you what you already know I'm sure, but:

  • you should be in a ListDataSource action when you use the line, so sender is one of those
  • the items are a list of dicts... so first you need the row number to get the correct entry from the list... and then you can use the entry as a dict to look up the title

Hope it helps.