By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,171 Members | 1,692 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,171 IT Pros & Developers. It's quick & easy.

Change treeview image

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.