[Mono-bugs] [Bug 426166] New: Checked-/ListBox with Sorted=true, Add gives wrong index and ItemCheck event

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Sep 14 14:12:28 EDT 2008


           Summary: Checked-/ListBox with Sorted=true, Add gives wrong index
                    and ItemCheck event
           Product: Mono: Class Libraries
           Version: 2.0
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: andyhume32 at yahoo.co.uk
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

With CheckedListBox with Sorted=true, Add(item,CheckState.Checked) and
Add(item,true) can return the wrong 'added at' index and thus produce an
incorrect ItemCheck event.

For instance if one adds items "cc","aa","dd","bb", then the 'added-at' index
in the four events and return values should be 0,0,2,1.  Mono always acts like
the item was appended, thus reporting indices 0,1,2,3.  The items do actually
appear at the correct position in the display however.

This affects ListBox too, Sorted=true being the issue.  There, obviously
affecting the Add(...) return index only -- there's no ItemCheck event.

This caused the app in which I found this to crash.  The wrong index in the
ItemCheck event caused a duplicate item to be added to a hashtable.  For
example in the example above, the apparent added items are the duplicates
{"cc","cc","dd","dd"}.  Eeek!

Unit-test cases in preparation.

A very simple fix isn't obvious; the _whole_ list is sorted after each item is
added, thus the item's real position is not known.  It would be better if the
item was just added at its sorted position (ArrayList.BinarySearch followed by
Insert).  Can the Sort method call then be removed?  If not is the sort
guaranteed to be stable?

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list