Bug 24587 - ArgumentOutOfRangeException when removing last item with focus from ListView
Summary: ArgumentOutOfRangeException when removing last item with focus from ListView
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-11-17 14:19 UTC by Chris Hubbard
Modified: 2014-12-01 11:56 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Proposed Fix (521 bytes, patch)
2014-11-17 15:23 UTC, Chris Hubbard

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Chris Hubbard 2014-11-17 14:19:48 UTC
If the last item in a ListView (using VirtualMode) is removed and that item has focus, then the ListView's focused_item_index is still referring to one item past the current number of items.

When the ListView receives an FocusChanged event, it attempts to access the current focus item to invalidate it and a ArgumentOutOfRangeException is thrown.

Currently, when the VirtualListSize value is changed, the selected indices is cleared.  The focus_item_index should also be cleared (set to -1).
Comment 1 Chris Hubbard 2014-11-17 15:23:18 UTC
Created attachment 8773 [details]
Proposed Fix
Comment 2 Chris Hubbard 2014-11-17 15:38:21 UTC
Created pull request: https://github.com/mono/mono/pull/1407