M
Marko Bozikovic
Hi all,
Using VS 2005, and I have a problem with removing nodes with custom images
from a treeview.
TreeView's ImageList is initially empty. First, I add a default/root image:
treeView.ImageList.Images.Add("Tree_Root", new Bitmap(Resources.Tree_Root));
treeView.ImageKey = "Tree_Root";
treeView.SelectedImageKey= "Tree_Root";
When adding nodes, I create a custom bitmap (each node gets a different icon),
add it to the image list and assign node's ImageKey and SelectedImageKey:
Bitmap nodeBmp = new Bitmap(...);
// ... draw on bitmap ...
string imageKey = ... // create a unique image key
treeView.ImageList.Images.Add(imageKey, nodeBmp);
newNode.ImageKey = imageKey;
newNode.SelectedImageKey= imageKey;
....
// add the new node
treeView.Nodes[0].Nodes.Add(newNode);
This works fine. The problem occurs when removing one of these nodes that is
not the last:
TreeNode node = // get the node to be removed...
// remove the node from the tree
node.Remove();
// remove node image from the ImageList
treeView.ImageList.Images.RemoveByKey(node.ImageKey);
The problem is that after removing a node, nodes that were below it get their
images screwed up: unselected image for a node is ok, but selected image is
painted as next node's image (the last node's selected image is painted
blank). I have checked their ImageKey and SelectedImageKey properties, and
they're the same, as expected.
If I don't remove node icons from the ImageList, things work ok.
Any ideas?
Thank you,
--
Marko
ICQ: 5990814
I'm not under the alkafluence of inkahol
that some thinkle peep I am.
It's just the drunker I sit here the longer I get.
Using VS 2005, and I have a problem with removing nodes with custom images
from a treeview.
TreeView's ImageList is initially empty. First, I add a default/root image:
treeView.ImageList.Images.Add("Tree_Root", new Bitmap(Resources.Tree_Root));
treeView.ImageKey = "Tree_Root";
treeView.SelectedImageKey= "Tree_Root";
When adding nodes, I create a custom bitmap (each node gets a different icon),
add it to the image list and assign node's ImageKey and SelectedImageKey:
Bitmap nodeBmp = new Bitmap(...);
// ... draw on bitmap ...
string imageKey = ... // create a unique image key
treeView.ImageList.Images.Add(imageKey, nodeBmp);
newNode.ImageKey = imageKey;
newNode.SelectedImageKey= imageKey;
....
// add the new node
treeView.Nodes[0].Nodes.Add(newNode);
This works fine. The problem occurs when removing one of these nodes that is
not the last:
TreeNode node = // get the node to be removed...
// remove the node from the tree
node.Remove();
// remove node image from the ImageList
treeView.ImageList.Images.RemoveByKey(node.ImageKey);
The problem is that after removing a node, nodes that were below it get their
images screwed up: unselected image for a node is ok, but selected image is
painted as next node's image (the last node's selected image is painted
blank). I have checked their ImageKey and SelectedImageKey properties, and
they're the same, as expected.
If I don't remove node icons from the ImageList, things work ok.
Any ideas?
Thank you,
--
Marko
ICQ: 5990814
I'm not under the alkafluence of inkahol
that some thinkle peep I am.
It's just the drunker I sit here the longer I get.