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
path: root/mcs/class
diff options
context:
space:
mode:
authorabrevet-dev <57099550+abrevet-dev@users.noreply.github.com>2019-12-09 17:51:28 +0300
committerAlexander Köplinger <alex.koeplinger@outlook.com>2019-12-09 17:51:28 +0300
commit3d83c7429ef9e66697b254c569d78f5da7cb5b42 (patch)
tree18a0db18d8db641266f66444701f6e43354a838a /mcs/class
parent612f2a8e885bfe1618374509376c4da13ce83c4e (diff)
[WinForms] No event should be triggered when calling ComboBox.Items.RemoteAt() (#18069)
* [WinForms] Fix wrong behavior when calling ComboBox.Items.RemoteAt() with index equals to SelectedIndex * [WinForms] Fix #10643 No event should be triggered when calling ComboBox.Items.RemoteAt() Fixes #10643
Diffstat (limited to 'mcs/class')
-rw-r--r--mcs/class/System.Windows.Forms/System.Windows.Forms/ComboBox.cs14
-rw-r--r--mcs/class/System.Windows.Forms/Test/System.Windows.Forms/ComboBoxTest.cs16
2 files changed, 23 insertions, 7 deletions
diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/ComboBox.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/ComboBox.cs
index e807b71190b..4d0b4010a43 100644
--- a/mcs/class/System.Windows.Forms/System.Windows.Forms/ComboBox.cs
+++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/ComboBox.cs
@@ -1695,7 +1695,7 @@ namespace System.Windows.Forms
}
}
- void SetSelectedIndex (int value, bool supressAutoScroll)
+ void SetSelectedIndex (int value, bool supressAutoScroll, bool triggerEvents = true)
{
if (selected_index == value)
return;
@@ -1718,9 +1718,11 @@ namespace System.Windows.Forms
if (listbox_ctrl != null)
listbox_ctrl.HighlightedIndex = value;
- OnSelectedValueChanged (EventArgs.Empty);
- OnSelectedIndexChanged (EventArgs.Empty);
- OnSelectedItemChanged (EventArgs.Empty);
+ if (triggerEvents) {
+ OnSelectedValueChanged (EventArgs.Empty);
+ OnSelectedIndexChanged (EventArgs.Empty);
+ OnSelectedItemChanged (EventArgs.Empty);
+ }
}
// If no item is currently selected, and an item is found matching the text
@@ -2134,9 +2136,7 @@ namespace System.Windows.Forms
throw new ArgumentOutOfRangeException ("index");
if (index < owner.SelectedIndex)
- --owner.SelectedIndex;
- else if (index == owner.SelectedIndex)
- owner.SelectedIndex = -1;
+ owner.SetSelectedIndex (owner.SelectedIndex - 1, false, false);
object removed = object_items [index];
diff --git a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/ComboBoxTest.cs b/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/ComboBoxTest.cs
index 530e5717de8..252068a95c4 100644
--- a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/ComboBoxTest.cs
+++ b/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/ComboBoxTest.cs
@@ -732,6 +732,22 @@ namespace MonoTests.System.Windows.Forms
Assert.IsTrue (cmbbox.ItemHeight > 0, "#21");
}
+ [Test]
+ public void RemoveAt_SelectedIndex ()
+ {
+ ComboBox cmbbox = new ComboBox ();
+ cmbbox.Items.AddRange (new object[] {"1", "2", "3"});
+ cmbbox.SelectedIndex = 0;
+ cmbbox.Items.RemoveAt (0);
+ Assert.AreEqual (0, cmbbox.SelectedIndex, "#A1");
+
+ cmbbox.Items.Clear ();
+ cmbbox.Items.AddRange (new object[] {"1", "2", "3"});
+ cmbbox.SelectedIndex = 2;
+ cmbbox.Items.RemoveAt (0);
+ Assert.AreEqual (1, cmbbox.SelectedIndex, "#A2");
+ }
+
//
// Exceptions
//