Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEberhard Beilharz <eb1@sil.org>2012-05-07 19:53:22 +0400
committerEberhard Beilharz <eb1@sil.org>2012-05-21 13:28:55 +0400
commit759d6501a5e2785497e034125f1508e5deea8e07 (patch)
tree47ef6c7a2426c31ce4769a716c14993d3b64c41a /mcs/class/Managed.Windows.Forms/Test
parent5a349bae393347c099dcc8fde2ec2b7ec1dcad6e (diff)
Xamarin-4921: Fix Listbox.SelectedItem after adding sorted item
When we add an item to a sorted listbox the indices of the selected items change and need to be updated. Change-Id: Ia32849fe10480354835dcd48b37d326d612af04f
Diffstat (limited to 'mcs/class/Managed.Windows.Forms/Test')
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ListBoxTest.cs53
1 files changed, 53 insertions, 0 deletions
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ListBoxTest.cs b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ListBoxTest.cs
index 3b2a6b950b4..c72999b8ac9 100644
--- a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ListBoxTest.cs
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ListBoxTest.cs
@@ -854,6 +854,59 @@ namespace MonoTests.System.Windows.Forms
}
Assert.AreEqual ((Array)expectedAddPositions, (Array)addedAtList.ToArray (typeof (int)), "addedAtList");
}
+
+ [Test]
+ public void SelectedIndexUpdated () // Xamarin bug 4921
+ {
+ using (Form f = new Form ()) {
+ f.ShowInTaskbar = false;
+
+ ListBox l = new ListBox ();
+ l.Sorted = true;
+ f.Controls.Add (l);
+
+ l.Items.Add ("B");
+ l.SelectedIndex = 0;
+
+ Assert.AreEqual (0, l.SelectedIndex);
+
+ l.Items.Add ("A");
+ Assert.AreEqual (1, l.SelectedIndex);
+ }
+ }
+
+ [Test]
+ public void SelectedIndexUpdated_MultiSelect () // Xamarin bug 4921
+ {
+ using (Form f = new Form ()) {
+ f.ShowInTaskbar = false;
+
+ ListBox l = new ListBox ();
+ l.Sorted = true;
+ l.SelectionMode = SelectionMode.MultiSimple;
+ f.Controls.Add (l);
+
+ l.Items.Add ("B");
+ l.Items.Add ("C");
+ l.SelectedIndex = 0;
+ l.SelectedIndex = 1;
+
+ Assert.AreEqual (2, l.SelectedIndices.Count);
+ Assert.AreEqual (0, l.SelectedIndices [0]);
+ Assert.AreEqual (1, l.SelectedIndices [1]);
+ Assert.AreEqual (2, l.SelectedItems.Count);
+ Assert.AreEqual ("B", l.SelectedItems [0]);
+ Assert.AreEqual ("C", l.SelectedItems [1]);
+
+ l.Items.Add ("A");
+ Assert.AreEqual (2, l.SelectedIndices.Count);
+ Assert.AreEqual (1, l.SelectedIndices[0]);
+ Assert.AreEqual (2, l.SelectedIndices[1]);
+ Assert.AreEqual (2, l.SelectedItems.Count);
+ Assert.AreEqual ("B", l.SelectedItems [0]);
+ Assert.AreEqual ("C", l.SelectedItems [1]);
+ }
+ }
}
[TestFixture]