Skip to content

Fix data binding fallback update for uncreated controls#14677

Open
abineshPalanisamy wants to merge 5 commits into
dotnet:mainfrom
abineshPalanisamy:Fix_Issue_13470
Open

Fix data binding fallback update for uncreated controls#14677
abineshPalanisamy wants to merge 5 commits into
dotnet:mainfrom
abineshPalanisamy:Fix_Issue_13470

Conversation

@abineshPalanisamy

@abineshPalanisamy abineshPalanisamy commented Jun 26, 2026

Copy link
Copy Markdown

Fixes #13470

Proposed changes

  • Update Binding.PushData(bool force) to avoid calling SetPropValue(null) when the binding is inactive and the target component has not yet been created.
  • Preserve the existing fallback behavior for inactive bindings when the target component is already created.
  • Add regression coverage in BindingTests for a bound NumericUpDown hosted on an inactive TabPage, where the target control is not yet created and a shared binding manager pushes updates to all bindings.
  • Add test coverage to verify that the binding still works correctly after the inactive tab page is selected and the target control becomes create

Root cause

  • The issue occurs when multiple controls are bound to the same data source and share the same BindingManagerBase.
  • When one bound control updates the data source, BindingManagerBase.PushData() attempts to push data to all associated bindings.
  • For a control hosted on an inactive TabPage, the target control may not be created yet.
  • In this state, the binding is inactive (IsBinding == false), but Binding.PushData(bool force) still executes the fallback path and calls SetPropValue(null).
  • For value-type target properties, this null assignment can be converted to a default value, such as 0.
  • In the reported scenario, NumericUpDown.Minimum is set to 8, so assigning 0 to NumericUpDown.Value causes ArgumentOutOfRangeException.

Customer Impact

  • Fixes a crash that can occur when a data-bound NumericUpDown is hosted inside an inactive or invisible container, such as an unselected TabPage.
  • Prevents invalid fallback/default values from being pushed into controls that are not yet created.
  • Improves reliability for applications that use data binding across multiple controls sharing the same data source.
  • Preserves existing behavior for inactive bindings whose target components are already created.

Regression?

  • No

Risk

  • Low.
  • The change is limited to the inactive binding fallback path in Binding.PushData(bool force).
  • Existing behavior is preserved for active bindings.
  • No public API changes.
  • No layout, rendering, accessibility, or designer behavior changes.

Screenshots

Before

Databinding_Before_fix.mp4

After

Databinding_After_fix.mp4

Test methodology

  • Reproduced the issue scenario described in the GitHub issue:

    • A TabControl contains two TabPage instances.
    • Each tab contains a NumericUpDown.
    • Both controls are bound to the same data source.
    • The second NumericUpDown is placed on an inactive tab page and has Minimum set to 8.
    • Changing the first NumericUpDown triggers a binding update through the shared BindingManagerBase.
    • Before the fix, this causes ArgumentOutOfRangeException because the inactive binding path pushes an invalid fallback value to the uncreated target control.
  • Verified that the updated Binding.PushData(bool force) behavior avoids calling SetPropValue(null) when the target component has not yet been created.

  • Added unit test coverage in BindingTests to validate that:

    • changing a bound control on the active tab does not throw when another bound NumericUpDown is on an inactive tab;
    • the inactive tab control receives the correct bound value after the tab is selected and the control becomes created;
    • the fix covers the binding lifecycle issue without changing the broader binding flow.
  • Verified that the existing inactive-binding fallback behavior is preserved when the target component is already created.

Accessibility testing

Test environment(s)

  • 11.0.100-preview.3.26170.106
Microsoft Reviewers: Open in CodeFlow

 Fix has been added for the issue.
Added unit test cases for the Fix_Issue_13470
Addressed the review correction for Fix_Issue_13470

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a WinForms data binding crash when BindingManagerBase.PushData() pushes updates to bindings whose target controls haven’t created their handles yet (e.g., controls hosted on an inactive TabPage). The change prevents the inactive-binding fallback path from pushing a null value into an uncreated control, which could otherwise coerce to an invalid default (like 0) and trigger ArgumentOutOfRangeException for value-type properties such as NumericUpDown.Value.

Changes:

  • Guard Binding.PushData(bool force) so the inactive-binding fallback (SetPropValue(null)) only runs when the target component is already created.
  • Add regression tests covering a bound NumericUpDown on an inactive tab page (no throw during shared manager updates; correct value after tab activation).
  • Add a test ensuring Binding.ReadValue() does not throw for an uncreated NumericUpDown with Minimum set.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs Avoids calling SetPropValue(null) for inactive bindings when the target control isn’t created, preventing invalid fallback writes.
src/test/unit/System.Windows.Forms/System/Windows/Forms/BindingTests.cs Adds regression coverage for inactive-tab NumericUpDown binding updates and uncreated-control ReadValue() behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Addressed the review correction for Fix_Issue_13470
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Databinding for an invisble NumericUpDown , may cause ArgumentOutOfRangeException

2 participants