Just as a side note: The ListView and similar controls do not work properly if you add the same object multiple times. In the original code you tried to add the same string twice, which would have led to problems sooner or later, even if you would not have
needed the indices. The new approach is correct: If you want to add the same item multiple times, you must create a "container" class (in this case called SimpleModel). Then you can create multiple containers with the same content and add them to
the ListView.

All replies

SelectedIndex does not help? Use Foo.SelectedIndex without "es" should work fine.

--James

<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support

Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

Thanks, but this doesn't really work. The reason is that if you have a list with, for example:

= "sunday","monday","sunday"

and the user selects both Sunday's, your output list has two items, both with index zero, when what is the case is index 0 and 2.

This is an important distinction. ListView is a View, not a Model, so the view is displaying only the Name property string on a much more complex Collection of 'unique' underlying objects. (for instance: sound.wav and sound.aif, same names yet different
objects).

This really looks like a .NET bug with the Extended feature of ListView. Clearly the interface that results in the collection SelectedItems can test for unique selected, but no other code option can? That seems like a big
problem.

Just as a side note: The ListView and similar controls do not work properly if you add the same object multiple times. In the original code you tried to add the same string twice, which would have led to problems sooner or later, even if you would not have
needed the indices. The new approach is correct: If you want to add the same item multiple times, you must create a "container" class (in this case called SimpleModel). Then you can create multiple containers with the same content and add them to
the ListView.