Skip to content

Update TreeView's TvnEndLabelEdit method to set label to null when no text has changed #13588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

LeafShi1
Copy link
Member

@LeafShi1 LeafShi1 commented Jun 12, 2025

Fixes #13583

Proposed changes

  • Update TreeView's TvnEndLabelEdit method to set label to null when no text has changed

Customer Impact

  • The edit state of TreeNode can be exited using the Enter key

Regression?

  • Yes

Risk

  • Minimal

Screenshots

Before

Pressing the Enter key when a TreeNode enters the edit state will cause an exception

beforeChange

After

When a TreeNode enters the edit state, press the Enter key, the node will exit the edit state

AfterChange

Test methodology

  • Manually

Test environment(s)

  • .net 10.0.0-preview.6.25310.107
Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor

@Copilot Copilot AI left a comment

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 updates the TreeView’s label edit handling to prevent exceptions when the text remains unchanged.

  • Refactors TvnBeginLabelEdit by removing a redundant duplicate condition check.
  • Updates TvnEndLabelEdit to pass null for the new label when the text is unchanged, preventing exception scenarios on Enter key presses.
Comments suppressed due to low confidence (1)

src/System.Windows.Forms/System/Windows/Forms/Controls/TreeView/TreeView.cs:2604

  • The condition continues to use the original newText variable rather than the value passed via e.Label. To ensure that the node edit is only finished when a change has occurred, consider checking e.Label instead of newText.
if (newText is not null && !e.CancelEdit && node is not null)

Copy link
Member

@ricardobossan ricardobossan left a comment

Choose a reason for hiding this comment

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

All LGTM!

Copy link
Member

@KlausLoeffelmann KlausLoeffelmann left a comment

Choose a reason for hiding this comment

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

Looks good to me.
If you decide for the simplified term, in which case you need a new approval, ask a colleague to approve - it's fine to merge from my side.

Copy link

codecov bot commented Jun 16, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 76.60716%. Comparing base (eb755df) to head (2d9ba3f).
Report is 21 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #13588         +/-   ##
===================================================
+ Coverage   76.60518%   76.60716%   +0.00197%     
===================================================
  Files           3235        3236          +1     
  Lines         639321      639452        +131     
  Branches       47314       47319          +5     
===================================================
+ Hits          489753      489866        +113     
- Misses        145996      146065         +69     
+ Partials        3572        3521         -51     
Flag Coverage Δ
Debug 76.60716% <75.00000%> (+0.00197%) ⬆️
integration 18.53370% <0.00000%> (-0.26486%) ⬇️
production 51.01007% <75.00000%> (-0.00796%) ⬇️
test 97.41283% <ø> (+0.01232%) ⬆️
unit 48.41130% <75.00000%> (+0.01717%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@LeafShi1 LeafShi1 merged commit 51412d9 into dotnet:main Jun 16, 2025
8 checks passed
@LeafShi1 LeafShi1 deleted the Issue_13583_fix_add_judgement_before_NodeLabelEditEventArgs branch June 16, 2025 02:55
KlausLoeffelmann pushed a commit to KlausLoeffelmann/winforms that referenced this pull request Jun 16, 2025
… text has changed (dotnet#13588)

* Update TreeView's TvnEndLabelEdit method to set label to null when no text has changed
@LeafShi1
Copy link
Member Author

/backport to release/9.0

Copy link
Contributor

Started backporting to release/9.0: https://github.com/dotnet/winforms/actions/runs/15725596969

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NodeLabelEditEventArgs.Label is wrong from .NET9
4 participants