0 Replies - 4397 Views - Last Post: 28 February 2012 - 10:15 AM Rate Topic: -----

#1 q12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 12-April 09

problem with adding treeview node

Posted 28 February 2012 - 10:15 AM

if (!treeView1.Nodes[i].Nodes[j].Text.Contains(mode01)) { treeView1.Nodes[i].Nodes.Add(mode01); }


if [treeView1.Nodes[i].Nodes[j].Text] does not contain mode01("mp"), add it, but one time only. Not every time you find it!So far, is working fine.
Same logic I want for [treeView1.Nodes[i].Nodes[j].Nodes.Add(mode02);] but I can not achieve it. Currently he is adding every time it find mode02("usa").

I have inserted a [for (int k = 0; k < treeView1.Nodes[i].Nodes[j].Nodes.Count; k++)] but I catch a very new and strange error, about an infinite loop that is eating too much from resources.
I tried to explain as best I could. Any questions are welcome.
The file that contain the data, have variations of string[Human "mp/usa/rifle" 0xb6b3].


foreach (var item in LListofEntity)//for    Human "mp/usa/rifle" 0xb6b3
{
    if (item.Contains("Human"))
    {
        for (int i = 0; i < treeView1.Nodes.Count; i++)
        {
            if (treeView1.Nodes[i].Text.Contains("Human"))
            {
                //extract "-string-"
                string cod0 = @""".*""";
                string itemCleanned = Regex.Match(item.ToString(), cod0).Value;
                //add mp
                string cod1 = @"""\w+";
                string mode01 = Regex.Match(itemCleanned, cod1).Value.Replace("\"", "");
                //add usa
                string cod2 = @"/.*/";
                string mode02 = Regex.Match(itemCleanned, cod2).Value.Replace("/", "");
                if (itemCleanned.Contains(mode01))   
                {
                tryagain:
                    if (treeView1.Nodes[i].Nodes.Count == 0) 
                    { treeView1.Nodes[i].Nodes.Add(mode01); goto tryagain; }
                    else
                    {
                        for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                        {
                            if (!treeView1.Nodes[i].Nodes[j].Text.Contains(mode01)) 
                            { treeView1.Nodes[i].Nodes.Add(mode01); }
                            if (!treeView1.Nodes.ContainsKey(mode02))
                            {
                                treeView1.Nodes[i].Nodes[j].Nodes.Add(mode02);
                            } 
 
                        }
                    }
                }
 
            }
 
        }
        treeView1.ExpandAll();
    }
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1