Bug 323384 (MONO80696) - '-1' is causing ArgumentException for ListBox
Summary: '-1' is causing ArgumentException for ListBox
Status: RESOLVED FIXED
Alias: MONO80696
Product: Mono: Class Libraries
Classification: Mono
Component: Windows.Forms (show other bugs)
Version: 1.2
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: 1_2
Assignee: Mike Kestner
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-01 13:42 UTC by Eric Albright
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
Proposed patch (743 bytes, patch)
2007-03-10 18:25 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:25:13 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".