-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix 13976: Enhance TreeNode.UpdateImage() to support inherited image keys and selected image rendering #13981
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
base: main
Are you sure you want to change the base?
Fix 13976: Enhance TreeNode.UpdateImage() to support inherited image keys and selected image rendering #13981
Conversation
…keys and selected image rendering
There was a problem hiding this 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 fixes an issue where TreeNodes without explicitly set images would incorrectly display the first image in a new ImageList when the TreeView's ImageList is changed. The fix implements a proper inheritance chain from TreeView to TreeNode for both regular and selected images, ensuring nodes maintain their intended images unless those images are removed from the new ImageList.
Key Changes:
- Added logic to resolve
ImageKeyandSelectedImageKeyfrom TreeView when not explicitly set on the node - Implemented a four-tier fallback hierarchy: Node ImageKey → Node ImageIndex → TreeView ImageKey → TreeView ImageIndex → default (0)
- Applied the same inheritance logic to both regular and selected images
src/System.Windows.Forms/System/Windows/Forms/Controls/TreeView/TreeNode.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/System/Windows/Forms/Controls/TreeView/TreeNode.cs
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #13981 +/- ##
===================================================
+ Coverage 77.14861% 77.15035% +0.00173%
===================================================
Files 3276 3276
Lines 645116 645161 +45
Branches 47705 47711 +6
===================================================
+ Hits 497698 497744 +46
- Misses 143727 143734 +7
+ Partials 3691 3683 -8
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All LGTM! Maybe add a test with the switch on and off, like done in https://github.com/ricardobossan/winforms/blob/7ccafe298bdf138f09585d3993c62768892f3d89/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewRowAccessibleObjectTests.cs#L2397-L2401
Waiting for @KlausLoeffelmann @JeremyKuhne to confirm this solution.
|
Fixes #13976
Proposed changes
PreserveUnassignedTreeNodeImagesto do following changeTreeNode.UpdateImage()by adding logic to resolveImageKeyandSelectedImageKeyfromTreeViewwhen not explicitly set on the node.SelectedImageKeyandSelectedImageIndexiSelectedImagewhen no valid image is available, allowing native fallback toiImageTVITEMW.maskincludesTVIF_SELECTEDIMAGEonly when applicableCustomer Impact
Regression?
Risk
Screenshots
Example project: TreeViewImageBug-master.zip
Before
TreeNodes without an image set are changed to the first image if the ImageList is changed.
BeforeChanges.mp4
After
TreeNodes without an image set are changed to the first image only when the original image is removed
AfterChanges.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow