Get Correct Index from Listview Selection after Filtering

Hi guys, sorry for the unclear title but I do not know what name to put or what to Google - I can only try my best to describe the situation. Sorry about this and please bear with me guys, thanks!

So basically, I have a google spreadsheet as my database. When I initialize my screen, my list view will show me all the elements of this spreadsheet.

When I do a listview.afterpicking, the next screen should show me all the relevant information pertaining to the element that I picked from listview. For example, if I pick the 2nd element (Index 2) in the screenshot above (Primary 2, Chemistry, East, S$60 - 70 per hour), it SHOULD bring me to this screen:


For example, let's say I search for the same job (Index 2) - Primary 2, Chemistry, East:


Ideally, it should bring me to the screen for Index 2. However, because after the search criteria, this job (which is index 2 in the initial listview has now become Index 1 in the new listview. The new screen then shows me the info for Index 1 instead of the ideally index 2.

How can I resolve this please? Any thread I can refer to? I am not able to find any...

Below are my blocks (I highly suspect the issue lies with the yellow-highlighted block codes):

Please let me know if you guys need any info, thank you!!

The issue is due to the filtering of the listview (the listview elements that are filtered each attain a new index) - you will need to use the same filter (do this in afterPicking with the listview.Selection) to find the correct data. There are many ways to handle this.

  1. you can avoid problems when switching screens and passing information by using virtual screens * Building Apps with Many Screens
  2. if you insist on using real Screens, you have to pass the data to the newly reopened screens. Using StartValue is not a particularly efficient way... use a TinyDB to store and pass the List perhaps
  3. read the responses on your previous post Filter by Criteria Function
  4. Your app is complex. A way to test for problems is to build small modules as separate Projects. Get those Projects to work (like switching screen experiments); then put them together.

Hi Tim,

Do you mean this?:

Faced an error as shown:


Hi Steve!

Tried using a virtual screen initially, but failed miserably with the coding blocks :'D ......

Something like this:


blocks (1)

Hi Tim,

You used 'list from csv row text' - however, when I used it, I got an error. Is it because in my google spreadsheet, each of my rows have multiple cells while each of the row you used in your example (a,b,c,d,e,....) has only one "cell" per row?

You will probably be getting a csv table back from google sheets, so use list from csv table

Hi Tim, thanks for the response!

Was wondering why is my list from csv table not working?


When I use list from csv row PLUS a pseudo csv file (Index2), and when I click on each element displayed in the listview, my Empty1.Text do say index of each element is 1, 2, 3, 4, etc.

However, when I use list from csv table PLUS my google spreadsheet file (responseContent), and when I click on each element displayed in the listview, my Empty1.Text shows that all my elements have an index of 0.

This appears to be the issue:

What is returned from the listview does not match the list, I will have a think about this....

Thanks Tim, I will try my best to think about this too

It's my first time making an app, and it is indeed both exciting and frustrating HAHA quite fun to be honest :slight_smile:

I am sure we have handled this issue before, I just can't remember what it was.... :upside_down_face:

The issue with filtering and selection index was never really resolved. My method works for a simple list, but for a list of lists, we would need to rebuild the listview.Selection output back into an AI2 list format for it to match items in the main list...ugh!

Try this:

Google Sheets can add a unique row number to each row, to help identifying rows by cell value. Insert a column A with value =ROWID() to get the unique identifiers.
Once you have the row ID of a desired row, you can go back and ask for just that row from Sheets using their SQL query URLs.
You can call it a job ID in your app, if you like.

Hi Tim,

Thanks! Have just tried, but apparently the brackets aren't remove and original index still shows '0' regardless which element I clicked :')


Same goes for this:


I see, you should use the Index of item in list item = 'selection' list = 'spreadsheet column' block to fix that

Hi Mayank, thanks for your response!

Hmm could you elaborate a little please? I don't quite understand😅


1 Like

I am asking you to use this block :point_up_2:. It is the easiest method I could think of.

Show listview.Selection
Run a Do It on split at spaces, what are you getting back?