简体   繁体   English

树视图的第一项为空

[英]First item of a treeview is null

I have one thread who will populate a TreeNode collection to not block the main Thread (windows form). 我有一个线程将填充TreeNode集合以不阻止主线程(Windows窗体)。 So i invoke by these line the TreeView.Nodes.Add command : 所以我通过这些行调用TreeView.Nodes.Add命令:

private void generateListeItems()
        {
            try
            {
                Item_Coll resultSet = connector.command_LIST();
                if(mainFormInvoke != null)
                    mainFormInvoke(formProgressBar, -1);
                TreeNode racine = new TreeNode();
                TreeNode NET = racine.Nodes.Add("Net");
                TreeNode LON = NET.Nodes.Add("LON");
                List<string> devices = new List<string>();

                TreeNode lastDevice = null;
                int lastDevice_index = -1;
                TreeNode lastDevice_fb = null;
                int lastDevice_fb_index = -1;
                int percentage = 0, lastPercentage = 0, treatedItem = 0;
                int nombreIndex = resultSet.Item.Count<Item>();
                foreach (Item index in resultSet.Item)
                {
                    string[] substring = index.UCPTname.Split('/');
                    if (lastDevice == null || substring[2] != lastDevice.Text)
                    {
                        lastDevice = LON.Nodes.Add(substring[2]);
                        lastDevice_index++;
                        lastDevice_fb_index = -1;
                    }

                    if (lastDevice_fb == null || substring[3] != lastDevice_fb.Text)
                    {
                        lastDevice_fb = lastDevice.Nodes.Add(substring[3]);
                        lastDevice_fb_index++;
                    }

                    lastDevice_fb.Nodes.Add(substring[4]);
                    dpDictionnary[index.UCPTname] = index;
                    lastPercentage = percentage;
                    percentage = ++treatedItem * (nombreIndex / 100);
                    if(percentage != lastPercentage)
                        mainFormInvoke(formProgressBar, 1);
                }

                mainFormInvoke((updatingListeInUI)liste.Nodes.Add, racine);
                mainFormInvoke(consoleWriter,string.Format("Connexion réussie, récupération de {0} éléments", resultSet.Item.Count<Item>()));
            }catch(SmartServerException e)
            {
                mainFormInvoke(consoleWriter, e.ToString());
            }

        }

And i got this : 而我得到了:

在此处输入图片说明

I don't want the first null element. 我不要第一个null元素。 How can i pass through this ? 我该如何通过?

TreeNode racine = new TreeNode("Root");
TreeNode NET = racine.Nodes.Add("Net");
TreeNode LON = NET.Nodes.Add("LON");

set default node to root as shown above 将默认节点设置为root,如上所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM