Tarasov
Tarasov

Reputation: 3685

How I can set a ImageIndex in my TreeView by a if statement?

hi how i can set a image for my treeView nodes... I have a parent and a child node.

here is my code:

private void btnShowLicstate_Click(object sender, EventArgs e)
        {
            treeLic.Nodes.Clear(); 

            string command = "\"C:\\lmxendutil.exe\" -licstatxml -host lwserv005 -port 6200";

            string output = ExecuteCommand(command);
            string final_output = output.Substring(90, output.Length - 90);

            XmlReader xr = XmlReader.Create(new StringReader(final_output));



            var xDoc = XDocument.Load(xr); 
                TreeNode root = new TreeNode();
                LoadTree(xDoc.Root.Element("LICENSE_PATH"), root);
                treeLic.Nodes.Add(root);

                treeLic.ImageList = imageList1; 

        }

 public void LoadTree(XElement root, TreeNode rootNode)
        {
            foreach (var e in root.Elements().Where(e => e.Attribute("NAME") != null))
            {
                var node = new TreeNode(e.Attribute("NAME").Value);
                rootNode.Nodes.Add(node);

                if (e.Name == "FEATURE")
                {
                    node.SelectedImageIndex = 1; 

                }
                else if (e.Name == "USER")
                {
                    node.SelectedImageIndex = 0;

                }

                LoadTree(e, node);
            }
        }

my problem is that i have everyone the same picture but i want for FEATURE the index 1 and for USER the Index 2 but why it don't work ? :(

Upvotes: 0

Views: 760

Answers (1)

Demarsch
Demarsch

Reputation: 1479

You should use ImageIndex property instead of SelectedImageIndex.

The first one is the index from ImageList for node in unselected state and the second one is applied when you select node using mouse, keyboard or through code.

Upvotes: 1

Related Questions