diff options
author | Matthew Baird <mbairdnz@gmail.com> | 2020-02-25 12:19:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-25 12:19:01 +0300 |
commit | 6b3a7986ef4e144feb73707453a385977f82690e (patch) | |
tree | 67802639385fdab13bf1df10a7b49d36c46cd334 /mcs | |
parent | 49deb4bcea3c7dd9af57420d8c210f15f5731802 (diff) |
Ensure ListView ItemCheck event can update the checked state (#18926) (#18937)
Fixes #18926
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/System.Windows.Forms/System.Windows.Forms/ListViewItem.cs | 2 | ||||
-rw-r--r-- | mcs/class/System.Windows.Forms/Test/System.Windows.Forms/ListViewItemTest.cs | 24 |
2 files changed, 26 insertions, 0 deletions
diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/ListViewItem.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/ListViewItem.cs index 05008ce8760..27430e30ff5 100644 --- a/mcs/class/System.Windows.Forms/System.Windows.Forms/ListViewItem.cs +++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/ListViewItem.cs @@ -273,6 +273,8 @@ namespace System.Windows.Forms ItemCheckEventArgs icea = new ItemCheckEventArgs (Index, new_value, current_value); owner.OnItemCheck (icea); + // consumers can update NewValue (e.g. to prevent checking an entry) + new_value = icea.NewValue; if (new_value != current_value) { // force re-population of list diff --git a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/ListViewItemTest.cs b/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/ListViewItemTest.cs index ce189e247de..2290b8b2d82 100644 --- a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/ListViewItemTest.cs +++ b/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/ListViewItemTest.cs @@ -677,6 +677,30 @@ namespace MonoTests.System.Windows.Forms item1.ToolTipText = null; Assert.AreEqual (String.Empty, item1.ToolTipText, "ToolTipText#1"); } + + [TestCase(CheckState.Checked, CheckState.Unchecked, CheckState.Unchecked)] + [TestCase(CheckState.Checked, CheckState.Unchecked, CheckState.Checked)] + [TestCase(CheckState.Unchecked, CheckState.Checked, CheckState.Unchecked)] + public void ListViewItemCheckEventChangesValue (CheckState currentValue, CheckState newValue, CheckState overrideNewValue) + { + ListView lv = new ListView (); + ListViewItem item1 = lv.Items.Add ("Item 1"); + item1.Checked = currentValue == CheckState.Checked; + + ItemCheckEventHandler checkEventHandler = (object sender, ItemCheckEventArgs args) => { + Assert.AreEqual (currentValue, args.CurrentValue, "#1"); + Assert.AreEqual (newValue, args.NewValue, "#2"); + args.NewValue = overrideNewValue; + }; + + lv.ItemCheck += checkEventHandler; + try { + item1.Checked = newValue == CheckState.Checked; + Assert.AreEqual (overrideNewValue == CheckState.Checked, item1.Checked, "#3"); + } finally { + lv.ItemCheck -= checkEventHandler; + } + } } [TestFixture] |