From fca897e865ffb0009edc1026259acc36cc62cb25 Mon Sep 17 00:00:00 2001 From: Abinesh p <120440951+abineshPalanisamy@users.noreply.github.com> Date: Tue, 26 May 2026 17:58:58 +0530 Subject: [PATCH 1/3] Fix has been added for the issue. Fix has been added for the issue. --- .../System/Windows/Forms/DataBinding/Binding.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs b/src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs index 59119b5352c..a5697dd2bcb 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs @@ -960,6 +960,17 @@ internal bool PullData(bool reformat, bool force) internal bool PushData(bool force) { + // Skip push if the target component is not created. + // + // Binding becomes active only after the component is created and has a valid + // BindingContext. Pushing values earlier may result in incorrect default + // assignments, as the target is not yet ready to receive updates. + + if (!ComponentCreated && !force) + { + return false; + } + object? dataSourceValue; Exception? lastException = null; From f3d10a4467f59417061385ac07011e8c48c9e824 Mon Sep 17 00:00:00 2001 From: Abinesh p <120440951+abineshPalanisamy@users.noreply.github.com> Date: Thu, 25 Jun 2026 12:33:06 +0530 Subject: [PATCH 2/3] Added unit test cases for the Fix_Issue_13470 Added unit test cases for the Fix_Issue_13470 --- .../System/Windows/Forms/BindingTests.cs | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/src/test/unit/System.Windows.Forms/System/Windows/Forms/BindingTests.cs b/src/test/unit/System.Windows.Forms/System/Windows/Forms/BindingTests.cs index 27723162b27..43c8ef7b190 100644 --- a/src/test/unit/System.Windows.Forms/System/Windows/Forms/BindingTests.cs +++ b/src/test/unit/System.Windows.Forms/System/Windows/Forms/BindingTests.cs @@ -615,6 +615,115 @@ public void Binding_WriteValue_Invoke_DoesNotCallBindingComplete(ControlUpdateMo Assert.Equal(0, callCount); } + [WinFormsFact] + public void Binding_PushData_InactiveTabPageNumericUpDown_DoesNotThrow() + { + BindableData data = new(); + using Form form = new(); + using TabControl tabControl = new() { Dock = DockStyle.Fill }; + using TabPage tabPage1 = new() { Text = "tabPage1" }; + using TabPage tabPage2 = new() { Text = "tabPage2" }; + using NumericUpDown num1 = new(); + using NumericUpDown num2 = new(); + + form.Controls.Add(tabControl); + tabControl.TabPages.Add(tabPage1); + tabControl.TabPages.Add(tabPage2); + + tabPage1.Controls.Add(num1); + tabPage2.Controls.Add(num2); + + num2.Minimum = 8; + + num1.DataBindings.Add( + nameof(num1.Value), + data, + nameof(BindableData.TestInt), + formattingEnabled: false, + DataSourceUpdateMode.OnPropertyChanged); + + num2.DataBindings.Add( + nameof(num2.Value), + data, + nameof(BindableData.TestInt2), + formattingEnabled: false, + DataSourceUpdateMode.OnPropertyChanged); + + form.Show(); + + Assert.Equal(tabPage1, tabControl.SelectedTab); + + Exception exception = Record.Exception(() => num1.Value = 41); + + Assert.Null(exception); + } + + [WinFormsFact] + public void Binding_PushData_InactiveTabPageNumericUpDown_BindsCorrectlyAfterPageActivation() + { + BindableData data = new(); + using Form form = new(); + using TabControl tabControl = new() { Dock = DockStyle.Fill }; + using TabPage tabPage1 = new() { Text = "tabPage1" }; + using TabPage tabPage2 = new() { Text = "tabPage2" }; + using NumericUpDown num1 = new(); + using NumericUpDown num2 = new(); + + form.Controls.Add(tabControl); + tabControl.TabPages.Add(tabPage1); + tabControl.TabPages.Add(tabPage2); + + tabPage1.Controls.Add(num1); + tabPage2.Controls.Add(num2); + + num2.Minimum = 8; + + num1.DataBindings.Add( + nameof(num1.Value), + data, + nameof(BindableData.TestInt), + formattingEnabled: false, + DataSourceUpdateMode.OnPropertyChanged); + + num2.DataBindings.Add( + nameof(num2.Value), + data, + nameof(BindableData.TestInt2), + formattingEnabled: false, + DataSourceUpdateMode.OnPropertyChanged); + + form.Show(); + + Exception exception = Record.Exception(() => num1.Value = 41); + Assert.Null(exception); + + tabControl.SelectedTab = tabPage2; + + Assert.Equal(18M, num2.Value); + } + + [WinFormsFact] + public void Binding_ReadValue_UncreatedNumericUpDownWithMinimum_DoesNotThrow() + { + BindableData data = new(); + using NumericUpDown num = new(); + + num.Minimum = 8; + + Binding binding = num.DataBindings.Add( + nameof(num.Value), + data, + nameof(BindableData.TestInt2), + formattingEnabled: false, + DataSourceUpdateMode.OnPropertyChanged); + + Assert.False(num.Created); + + Exception exception = Record.Exception(binding.ReadValue); + + Assert.Null(exception); + } + private class SubBinding : Binding { public SubBinding(string propertyName, object dataSource, string dataMember) : base(propertyName, dataSource, dataMember) @@ -627,4 +736,38 @@ public SubBinding(string propertyName, object dataSource, string dataMember) : b public new void OnParse(ConvertEventArgs cevent) => base.OnParse(cevent); } + + private sealed class BindableData : INotifyPropertyChanged + { + private int _testInt = 42; + private int _testInt2 = 18; + + public event PropertyChangedEventHandler PropertyChanged; + + public int TestInt + { + get => _testInt; + set + { + if (_testInt != value) + { + _testInt = value; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TestInt))); + } + } + } + + public int TestInt2 + { + get => _testInt2; + set + { + if (_testInt2 != value) + { + _testInt2 = value; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TestInt2))); + } + } + } + } } From 6fe2c7f81604b226f017d27b43ff8fedd8d6ef90 Mon Sep 17 00:00:00 2001 From: Abinesh p <120440951+abineshPalanisamy@users.noreply.github.com> Date: Thu, 25 Jun 2026 17:24:10 +0530 Subject: [PATCH 3/3] Addressed the review correction for Fix_Issue_13470 Addressed the review correction for Fix_Issue_13470 --- .../System/Windows/Forms/DataBinding/Binding.cs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs b/src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs index a5697dd2bcb..a75bacae571 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs @@ -960,17 +960,6 @@ internal bool PullData(bool reformat, bool force) internal bool PushData(bool force) { - // Skip push if the target component is not created. - // - // Binding becomes active only after the component is created and has a valid - // BindingContext. Pushing values earlier may result in incorrect default - // assignments, as the target is not yet ready to receive updates. - - if (!ComponentCreated && !force) - { - return false; - } - object? dataSourceValue; Exception? lastException = null; @@ -997,7 +986,7 @@ internal bool PushData(bool force) SetPropValue(controlValue); _state.ChangeFlags(BindingStates.Modified, false); } - else + else if (ComponentCreated) { SetPropValue(null); }