Dictionary not returning correct value

So I have a listBox and I am storing a dictionary in the RowTag for each row added to the listBox.

When a row is clicked on I then read the data from the rowTag I get the dictionary.

Oddly no matter what row I click on the dictionary I retrieve from the row is the last one added to the listbox.

I am storing the data using the following code

listEvents.RowTag(listEvents.LastIndex) = storageData

I then retrieve it in another method using

dim eventDateData as New Xojo.Core.Dictionary eventDateData = listEvents.RowTag(row)

I know I am getting the correct row as the title I am reading directly from the row is the one I click on.

Any idea why I am always retrieving the last dictionary I store?

Probably because you’ve stored the same Dictionary instance to every row.

Also, FYI, in this code, “new” is unnecessary:

dim eventDateData as New Xojo.Core.Dictionary
eventDateData = listEvents.RowTag(row)

All this does is create a new instance of a Dictionary only to be discarded immediately when the Dictionary from the RowTag is fetched. Instead:

dim eventDateData as Xojo.Core.Dictionary
eventDateData = listEvents.RowTag(row)

Or even simply:

dim eventDateData as Xojo.Core.Dictionary = listEvents.RowTag(row)

Sorta. I was creating a single dictionary instance and then simply updating it instead of creating a new one. I modified the code so that the definition is inside the loop and it fixed the issue.