0

I´m working in a TreeView project, where I need to read a file and show the information in the TreeView, but when I create a third node, throws me a NullException.

        treeView1.Nodes.Clear();

        // Recorre las líneas
        foreach (var line in lines)
        {
            // Separa el contenido de la línea por el caracter ,
            var parts = line.Split(',');
            if (parts.Length >= 0)
            {
                //RAÍZ
                // Si no está creado el nodo con la primera parte lo añade
                if (!treeView1.Nodes.ContainsKey(parts[0]))
                    treeView1.Nodes.Add(parts[0], parts[0]);


                // Seleccionamos el nodo padre con la primera parte
                var firstLevel = treeView1.Nodes[parts[0]];
                // Si no existe un nodo con la segunda parte, lo crea
                if (!firstLevel.Nodes.ContainsKey(parts[1]))
                    firstLevel.Nodes.Add(parts[1], parts[1]);


                // Seleccionamos el nodo padre con la segunda parte
                var secondLevel = treeView1.Nodes[parts[1]];
                // Si no existe un nodo con la tercera parte, lo crea
                if (!secondLevel.Nodes.ContainsKey(parts[2]))
                    secondLevel.Nodes.Add(parts[2], parts[2]);

Process with parts[1]

Process with parts[1]

Process with parts[1]

If in this part I change the 1 to 0 in var secondLevel = treeView1.Nodes[parts[0]], it works but never creates the third node

Sorry, Is my first time posting in SOF, so I can´t put images

D Stanley
  • 139,271
  • 11
  • 154
  • 219
  • We already helped you. Note that your question is marked as being a duplicate of another question. Follow the link to that other question, and read the answer(s) there for advice on how to trouble-shoot / solve this particular problem. –  Sep 20 '18 at 18:22
  • The reason you “can´t put images” is because [images of errors are not helpful](http://idownvotedbecau.se/imageofanexception/). Post the full error message, not just a few words, to your question. – Dour High Arch Sep 21 '18 at 00:03

0 Answers0