What is the proper way to clear the selected ListView element? I've tried ListView.Refresh but that doesn't deselect the element, and when I try to set ListView.selectedIndex to -1 it throws an error saying the value can't be negative. Thank you!
I am encountering a similar difficulty. There seems to be no way of to modify the list view selection. I am implementing a ListView in which the user can delete the selected items. This works by removing the items from the source list, but it seems that after I refresh the list view, items which were not selected before, become selected. It is as if the selection information has been mapped to other items. Also, it would be great if we could get access to all selected indices. I am using a list view with Multiselect caps. It would make sense that I should be able to retrieve a list with all selected item indices. This is actually useful in situations where you have to operate with the selected items because you don't have to store additional information yourself.
There is a ClearSelection() method but it's marked protected. It's something that needs to be fixed. In the mean time you can inherit from ListView and expose it or copy our ListView implementation and marking it public (see below). See my reply in your original thread: https://forum.unity.com/threads/lis...script-shift-multiselect.738353/#post-4927310
How does the implementation work? I tried to copy the ListView script but it just throws errors because many functions and properties arent available. I dont think your solution suggests I import all other dependent scripts too?
I haven't really looked at this, but simply extending it would be something like: Code (csharp): public new void ClearSelection() { base.ClearSelection(); } Copying over all of the code probably won't work easily, without a lot of effort re-implementing internal methods being called out to. If you're going to go that far, just use reflection to call the protected ClearSelection method externally- it'd be less work. That said, it looks like it's public now anyways though.