Visual Basic > Visual Basic Forums > Visual Basic General > Icon in TreeView changes upon clicking node
Ask a questionAsk a question
 

AnswerIcon in TreeView changes upon clicking node

  • Wednesday, November 04, 2009 4:17 AMExcelMonkey Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a TreeView.  I am building the nodes within a For/Each loop.  I then add icons to each node from an ImageList control.  The icons load properly.  However I am noticing that when I click onto the nodes, after the TreeView is built, the selected node defaults to another image.  It seems to always default to the image which has the index of whatever is set in the Properties Windows for the Control for ImageIndex.

    So assume that the ImageIndex is set to 0 in the Properties Window.  If I add ImageIndex 1 to the node at run time (See Below), ImageIndex 1 show up but once I click onto this node the icons switches to ImageIndex 0.  Why.

    TreeView5.SelectedNode = FileNode
    TreeView5.SelectedNode.ImageIndex = 1

    Thanks

    EM

Answers

  • Wednesday, November 04, 2009 6:00 AMbdbodger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Each Treeview Node has an ImageIndex and a SelectedImageIndex set both to the same index number .
    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    • Marked As Answer byExcelMonkey Thursday, November 05, 2009 3:26 PM
    •  

All Replies

  • Wednesday, November 04, 2009 5:44 AMExcelMonkey Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    ok so as I understand it, the TreeView5.ImageIndex = 0 sets the default icon when selected.  So I can the question is, how do you set this so that it does not change the icon when selected?

    Thanks

    EM
  • Wednesday, November 04, 2009 6:00 AMbdbodger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Each Treeview Node has an ImageIndex and a SelectedImageIndex set both to the same index number .
    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    • Marked As Answer byExcelMonkey Thursday, November 05, 2009 3:26 PM
    •  
  • Thursday, November 05, 2009 3:26 PMExcelMonkey Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Perfect thanx!

    EM