473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 16745
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nick Calladine | last post by:
Is this possible to ... I wish to get the value of a dropdown select but gets is indexable value (dont know if that is the right term) if that is possible (the position it assigned get assigned...
2
by: Mark Kamoski | last post by:
How can one change an image url at runtime? (Note, the image exists in a user control.) This is the image tag on the ascx... <asp:image id="TopBanner" runat="server"></asp:image> ....but...
3
by: Miguel Dias Moura | last post by:
Hello, i know how to hide a table according to a condition: <table runat="server" visible='<%# dataSetBibliotecas.FieldValue("Titulo", Container) <> "" %>'... Now I am trying to change the...
0
by: Jacek Francuz | last post by:
Hi! How can I change button image end send file to Client in one request? I try to change image in first step and I add onstartupscript: "Form1.submit()" and then in second step I send...
2
by: Miguel Dias Moura | last post by:
Hello, i know how to hide a table according to a condition: <table runat="server" visible='<%# dataSetBibliotecas.FieldValue("Titulo", Container) <> "" %>'... Now I am trying to change the...
0
by: Gavin | last post by:
Can anybody give me a code example of how to change an image size and resolution. I can upload a image file to a PostedFile. But what I need to do is change the size of that image and save it to my...
5
by: Laphan | last post by:
Hi All Just to confirm, is it true that you can't change the image of an <INPUT TYPE="IMAGE".... from within a CSS styelsheet? I know the standard command is SRC="....", but there doesn't seem...
3
by: vartana | last post by:
I will be getting the background url dynamically using ajax and html. I have set an id=boxFooter_002 to my div and have ...
5
by: danmoran | last post by:
I would like to change the image on animageButton as this is clicked by the user. when the master page is loaded it shows the btnHome.ImageUrl = "~/images/home.jpg"; But when the user clicks on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.