469,903 Members | 1,519 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Change treeview image

Hi to all,

i have a treeview that i put some nodes in it with their repsective images.
If i try to change the image and set it to some other ImageList index,
nothing happens.

The code i use is:

private void ChangeServantStatus(string servant, ServantStatus status)
{
foreach (TreeNode n in treServants.Nodes[0].Nodes)
{
if (n.Text == servant)
{
n.ImageIndex = 4;
n.SelectedImageIndex = 4; break;
}
}
return;
}
I search ms support and i found the following article
"PRB: Windows Forms TreeView Control Does Not Handle State Image Lists in
Visual C# .NET"
that contains stuff like Interop Services, IntPtr, and SendMessage calls.

I do not think that there is no other way to handle this,
can anyone help me with this?
I just need a simple way to change an image in a TreeView.

thanks a lot for any help
anthonyb
Nov 15 '05 #1
1 16364
If you are trying to specify image indices in a DIFFERENT
ImageList, than you need to change the ImageList property
for the TreeView to the ImageList your trying to get the
images from.

ie.

private void ChangeServantStatus(string servant,
ServantStatus status)
{
// Change the TreeView's ImageList Property.
// If your TreeView is named treeView1, and the
// second ImageList is imageList2, then it would be...
treeView1.ImageList = imageList2;

foreach (TreeNode n in treServants.Nodes[0].Nodes)
{
if (n.Text == servant)
{
n.ImageIndex = 4;
n.SelectedImageIndex = 4; break;
}
}
return;
}
If that is infact what you are trying to do, I would
suggest putting all the images in the same ImageList and
just reference the index you want and not worry about
having to change the ImageList.

Keep in mind that in your sample code, it will only
change the first occurance of a TreeNode with the text
to "servant" (don't forget your quotes). If you wanted to
change all TreeNode's with that text, then remove the
break in the if statement.

Hope this helps,
Jacob

-----Original Message-----
Hi to all,

i have a treeview that i put some nodes in it with their repsective images.If i try to change the image and set it to some other ImageList index,nothing happens.

The code i use is:

private void ChangeServantStatus(string servant, ServantStatus status){
foreach (TreeNode n in treServants.Nodes[0].Nodes)
{
if (n.Text == servant)
{
n.ImageIndex = 4;
n.SelectedImageIndex = 4; break;
}
}
return;
}
I search ms support and i found the following article
"PRB: Windows Forms TreeView Control Does Not Handle State Image Lists inVisual C# .NET"
that contains stuff like Interop Services, IntPtr, and SendMessage calls.
I do not think that there is no other way to handle this,
can anyone help me with this?
I just need a simple way to change an image in a TreeView.
thanks a lot for any help
anthonyb

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mark Kamoski | last post: by
3 posts views Thread by Miguel Dias Moura | last post: by
reply views Thread by Jacek Francuz | last post: by
2 posts views Thread by Miguel Dias Moura | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.