2007-12-19 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Thu, 20 Dec 2007 05:16:25 +0000 (05:16 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Thu, 20 Dec 2007 05:16:25 +0000 (05:16 -0000)
* ListBox.cs: Both FindString and FindStringExact methods must do an
case insensitive search, should allow the last valid index to be
passed in the overload taking an initial index, and should also
continue searching from the top back to the specified index when it
reaches the bottom.

svn path=/trunk/mcs/; revision=91677

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs

index fcd69a93c200a22aa23fcedc45b041c996c98a8a..83e1ddf5c1a0d6c0d0de4c3e54d327c1a47f2ad6 100644 (file)
@@ -1,3 +1,11 @@
+2007-12-19  Carlos Alberto Cortez <calberto.cortez@gmail.com>
+
+       * ListBox.cs: Both FindString and FindStringExact methods must do an
+       case insensitive search, should allow the last valid index to be
+       passed in the overload taking an initial index, and should also
+       continue searching from the top back to the specified index when it
+       reaches the bottom.
+
 2007-12-19  Jonathan Pobst  <monkey@jpobst.com>
 
        * TextControl.cs: Apply patch from Luke Page that fixes a scrolling
index 66d1ac1c67e15c0a3edece2f7b26d73cc5978d8e..ecc873879d0103ee2f3af11052dc31793e22d31e 100644 (file)
@@ -32,6 +32,7 @@ using System.Collections;
 using System.ComponentModel;
 using System.ComponentModel.Design;
 using System.ComponentModel.Design.Serialization;
+using System.Globalization;
 using System.Reflection;
 using System.Runtime.InteropServices;
 
@@ -749,13 +750,21 @@ namespace System.Windows.Forms
                        if (Items.Count == 0)
                                return -1; // No exception throwing if empty
 
-                       if (startIndex < -1 || startIndex >= Items.Count - 1)
+                       if (startIndex < -1 || startIndex >= Items.Count)
                                throw new ArgumentOutOfRangeException ("Index of out range");
 
-                       startIndex++;
-                       for (int i = startIndex; i < Items.Count; i++) {
-                               if ((GetItemText (Items[i])).StartsWith (s))
+                       startIndex = (startIndex == Items.Count - 1) ? 0 : startIndex + 1;
+
+                       int i = startIndex;
+                       while (true) {
+                               string text = GetItemText (Items [i]);
+                               if (CultureInfo.CurrentCulture.CompareInfo.IsPrefix (text, s,
+                                               CompareOptions.IgnoreCase))
                                        return i;
+
+                               i = (i == Items.Count - 1) ? 0 : i + 1;
+                               if (i == startIndex)
+                                       break;
                        }
 
                        return NoMatches;
@@ -771,13 +780,19 @@ namespace System.Windows.Forms
                        if (Items.Count == 0)
                                return -1; // No exception throwing if empty
 
-                       if (startIndex < -1 || startIndex >= Items.Count - 1)
+                       if (startIndex < -1 || startIndex >= Items.Count)
                                throw new ArgumentOutOfRangeException ("Index of out range");
 
-                       startIndex++;
-                       for (int i = startIndex; i < Items.Count; i++) {
-                               if ((GetItemText (Items[i])).Equals (s))
+                       startIndex = (startIndex + 1 == Items.Count) ? 0 : startIndex + 1;
+
+                       int i = startIndex;
+                       while (true) {
+                               if (String.Compare (GetItemText (Items[i]), s, true) == 0)
                                        return i;
+
+                               i = (i + 1 == Items.Count) ? 0 : i + 1;
+                               if (i == startIndex)
+                                       break;
                        }
 
                        return NoMatches;