Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,

Am working on winForm application , I browse an XML file to a TreeView. Then I want to delete some nodes , actually i can select one node then delete it.
My question/problem is :
I have another nodes with the same attribute value


XML
<object id="100" name="toto">
  <child id="1200"/>
  <child id="1300"/>
<object/>
<object id="1200" name="toto"/>


I want to select and delete the object with the id = 1200 , then it's delete also the child with the id =1200.
It's an exemple , so globaly i want to delete all node having the similar id attribute value as the node selected.
it's possible ? if yes how ? can u help me to start this plz :)
Posted
Updated 25-Nov-14 2:14am
v2
Comments
BillWoodruff 25-Nov-14 9:28am    
You want to delete Nodes from the TreeView at run-time ... or, you want to delete objects in the Xml and re-load the TreeView ? Are you using a sub-classed TreeNode that contains a field named 'id, or are you assigning the value of 'id in the Xml to the TreeNode's Tag property ?
Member 11192477 25-Nov-14 10:03am    
I want to delete Nodes from TreeView , then i save the new state of treeview in the existing xml file or a new one , i think is the same think if i delete directly from the xml file.
I browse the XML file in my treeview
BillWoodruff 25-Nov-14 16:31pm    
Okay, what is the linkage between a given node and its "id" and/or "name" property ? Are you storing that information in the TreeNode's .Tag property, or do you have something like a Dictionary where the Key is the TreeNode, and the Value an instance of a Class, or Struct, or a generic List of attributes ?

Are you using LinqToXml to parse the Xml into some kind of data structure ?

What you want is very easy to achieve, I think, but without knowing the "mapping" of Nodes to attributes, there's no point in making a guess about the solution.

Well, yes, if you modified the Xml, cleared the TreeNodes, and re-built the Tree, that would work, but that's doing it the hard way.
John C Rayan 19-Feb-15 11:13am    
if you want to try it on xml then you could use xpath //*[@id='1200']. It will select all elements from all levels that match id=1200

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900