Skip to content

Conversation

@LeafShi1
Copy link
Member

@LeafShi1 LeafShi1 commented Oct 22, 2025

Fixes #13976

Proposed changes

  • Add switch PreserveUnassignedTreeNodeImages to do following change
    • Update TreeNode.UpdateImage() by adding logic to resolve ImageKey and SelectedImageKey from TreeView when not explicitly set on the node.
    • Improved fallback handling for both image and selected image index:
      • Priority: ImageKey → ImageIndex → TreeView.ImageKey → TreeView.ImageIndex → default (0)
      • Same logic applied to SelectedImageKey and SelectedImageIndex
    • Prevented setting iSelectedImage when no valid image is available, allowing native fallback to iImage
    • Ensured TVITEMW.mask includes TVIF_SELECTEDIMAGE only when applicable

Customer Impact

  • After this fix, when the TreeView’s ImageList changes, TreeNodes without explicitly set images will continue to display their original default image—if it still exists. If the default image has been removed, they will fall back to showing the first image in the new ImageList.

Regression?

  • No

Risk

  • Minimal

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

  • Manually

Test environment(s)

  • .net 10.0.0-rc.1.25405.103
Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor

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 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 ImageKey and SelectedImageKey from 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

@codecov
Copy link

codecov bot commented Oct 22, 2025

Codecov Report

❌ Patch coverage is 27.27273% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.15035%. Comparing base (76554a2) to head (b2d5757).
⚠️ Report is 11 commits behind head on main.

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     
Flag Coverage Δ
Debug 77.15035% <27.27273%> (+0.00173%) ⬆️
integration 18.99029% <0.00000%> (+0.01169%) ⬆️
production 52.01441% <27.27273%> (+0.00601%) ⬆️
test 97.40955% <ø> (+0.00007%) ⬆️
unit 49.45750% <27.27273%> (-0.00549%) ⬇️

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.

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.

@LeafShi1
Copy link
Member Author

LeafShi1 commented Oct 27, 2025

All LGTM! Maybe add a test with the switch on and off

Waiting for @KlausLoeffelmann @JeremyKuhne to confirm this solution.

UpdateImage() sends a message to the Win32 API via SendMessage to update the UI, but does not change the ImageKey or ImageIndex properties of the TreeNode. Therefore, to verify whether the TreeNode displays the correct image on the UI, image rendering or screenshot comparison is required, which is not possible in Unit test.

@LeafShi1 LeafShi1 added the waiting-review This item is waiting on review by one or more members of team label Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Infrastructure waiting-review This item is waiting on review by one or more members of team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TreeNodes without an image set are changed to the default image if ImageList is changed

2 participants