-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
.NET version
.NET Framework 4.8, .NET 8, .NET 9
Did it work in .NET Framework?
No
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No response
Issue description
When an image is added to or removed from an ImageList which is used for a TreeView, all nodes which don't have their own image set and thus use the default image of the TreeView, use the first image in the ImageList afterwards and not the set default image.
It looks like there is a bug in TreeNode.UpdateImage
winforms/src/System.Windows.Forms/System/Windows/Forms/Controls/TreeView/TreeNode.cs
Line 2196 in 4edb501
| internal unsafe void UpdateImage() |
winforms/src/System.Windows.Forms/System/Windows/Forms/Controls/TreeView/TreeView.cs
Line 1710 in 4edb501
| private void ImageListChangedHandle(object? sender, EventArgs e) |
It doesn't check IsSpecialImageIndex and use the TreeView's imageIndexer in this case, like the UpdateNode method above.
Steps to reproduce
- Create an ImageList with a few images.
- Create a TreeView and set the ImageList.
- Set one of the images as default on the TreeView using
treeView.ImageKey. Do not use the first image in the ImageList. - Add some nodes to the tree. Do not set an image on them so that they get the default tree-wide image.
- Add or remove an image from the image list at runtime.
- Observe that the image on the nodes, which had the default set, gets set to the first image of the ImageList instead of keeping their image. The TreeView is not directly modified in step 5.
See https://github.com/jmairboeck/TreeViewImageBug for an example project to reproduce the bug.