Skip to content

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

@jmairboeck

Description

@jmairboeck

.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

which is called from the ImageListChangedHandle handler:
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

  1. Create an ImageList with a few images.
  2. Create a TreeView and set the ImageList.
  3. Set one of the images as default on the TreeView using treeView.ImageKey. Do not use the first image in the ImageList.
  4. Add some nodes to the tree. Do not set an image on them so that they get the default tree-wide image.
  5. Add or remove an image from the image list at runtime.
  6. 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.

Metadata

Metadata

Assignees

Labels

🪲 bugProduct bug (most likely)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions