diff options
author | Steven Boswell II <ulatekh@yahoo.com> | 2012-06-09 23:38:25 +0400 |
---|---|---|
committer | Thomas Goldstein <stifu@free.fr> | 2012-06-09 23:38:40 +0400 |
commit | ecd410269466799c8bde71fc55ea9bf2a052c364 (patch) | |
tree | 8f729057ecd8d9b3953cb879b7bab207709ff3cc /mcs/class/Managed.Windows.Forms/Test | |
parent | f2d8973cce5480f351bb92ed5f5c658ec40098fb (diff) |
Decrement ComboBox SelectedIndex when an item before the selected index gets removed. Fixes Xamarin bug 5595.
Diffstat (limited to 'mcs/class/Managed.Windows.Forms/Test')
-rw-r--r-- | mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ComboBoxTest.cs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ComboBoxTest.cs b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ComboBoxTest.cs index 1c32e4135c1..3a75b2c5cc7 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ComboBoxTest.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ComboBoxTest.cs @@ -999,6 +999,69 @@ namespace MonoTests.System.Windows.Forms } [Test] + // Xamarin bug 5595 + // https://bugzilla.xamarin.com/show_bug.cgi?id=5595 + public void SelectionWithDeletion() + { + Form form = null; + + try + { + // Create a form with a combo box. + form = new Form (); + form.ShowInTaskbar = false; + ComboBox cb = new ComboBox (); + cb.DropDownStyle = ComboBoxStyle.DropDownList; + cb.Parent = form; + form.Show (); + + // Add some items to the combo box. + cb.Items.Add ("Item 0"); + cb.Items.Add ("Item 1"); + cb.Items.Add ("Item 2"); + + // Select the last item. + cb.SelectedIndex = 2; + Assert.AreEqual(2, cb.SelectedIndex, "SWD1"); + + // Show the combo box's dropdown. + cb.DroppedDown = true; + + // Display the results. + Application.DoEvents(); + + // Hide the combo box's dropdown. + cb.DroppedDown = false; + + // Display the results. + Application.DoEvents(); + + // Delete an item before the selection. + // That should move the selection down. + // Before the bug fix, it would remain 2. + cb.Items.RemoveAt (1); + Assert.AreEqual(1, cb.SelectedIndex, "SWD2"); + + // Show the combo box's dropdown. + // Before the bug fix, this would throw an + // ArgumentOutOfRangeException, because the + // selected index was still 2, and hence + // invalid.) + cb.DroppedDown = true; + Assert.AreEqual(1, cb.SelectedIndex, "SWD3"); + + // Display the results. + Application.DoEvents(); + } + finally + { + // Get rid of the form. + if (form != null) + form.Dispose (); + } + } + + [Test] public void SelectionWithClear() { ComboBox cb = new ComboBox(); |