Bugzilla – Bug 323384
'-1' is causing ArgumentException for ListBox
Last modified: 2007-09-15 21:24:06 UTC
---- Reported by albright@wesay.org 2007-02-01 06:42:40 MST ---- Description of Problem: When ListBox.SelectedIndex is assigned -1 to clear selection, causes System ArgumentException to be thrown. Steps to reproduce the problem: 1. Create a ListBox. 2. Assign -1 in SelectedIndex 3. Kaboom Actual Results: System.ArgumentException throws '-1' is not a valid value Stack is: at System.Windows.Forms.ScrollBar.set_Value (Int32 value) at (wrapper remoting-invoke-with-check) System.Windows.Forms.ScrollBar:set_Value (int) at System.Windows.Forms.ListBox.UpdateTopItem () at System.Windows.Forms.ListBox.set_SelectedIndex (Int32 value) Expected Results: Unselect ListBox How often does this happen? Additional Information: ---- Additional Comments From georgegiolfan@yahoo.com 2007-02-07 08:59:40 MST ---- If I understand correctly, top_index is the index of the first visible item. If this is the case, setting it to -1 does not make sense. I propose changing ListBox.SelectedIndex so that if (value < top_index) { top_index = value; UpdateTopItem (); } else { int rows = items_area.Height / ItemHeight; if (value >= (top_index + rows)) { top_index = value - rows + 1; UpdateTopItem (); } } is executed only if value is not -1. ---- Additional Comments From georgegiolfan@yahoo.com 2007-03-10 11:25:05 MST ---- Created an attachment (id=171377) Proposed patch ---- Additional Comments From mkestner@ximian.com 2007-03-27 11:46:41 MST ---- revision 75022. Imported an attachment (id=171377) Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>ubuntu dapper</cf_op_sys_details> Unknown operating system other. Setting to default OS "Other".