C# Treeview checking if node exists

前端 未结 8 762
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 12:42

I\'m trying to populate a treeview from an XmlDocument. The Root of the tree is set as \'Scripts\' and from the root the next level should be \'Departments\' which is within the

8条回答
  •  天命终不由人
    2021-01-23 13:14

    Not sure about the document structure...
    Couldn't you use Linq to Xml, load the document and get the distinct row ( row = department?) and consider only those elements to create a TreeNode? It is more efficient than trying to find if a node with such a text has already been added. ex:

     var rows =      (  from row  in XDocument.Load(document).Root.Elements("row")
                        select row
                     ).Distinct(new SampleElementComparerOnNameAttribute());
    

    Here the EqualityComparer is made on the "name" attribute value assuming the doc structure to be

    
    

提交回复
热议问题