I'm looking for a way to hides node in a tree. I'm filtering a node with a node type, this is my original structure:
root
+FolderA
-File1
-File2
-File3
+FolderB
-File4
-File5
+FolderB-1
-File6
This is what I'm trying to do:
+root
-File1
-File2
-File3
-File4
-File5
-File6
I have created my class XNode with a type and a list of childrens. (this is pseudo language for abbreviation)
Class XNode
MyType type;
string Name;
List<XNode> childrens;
End Class
I have created a factory class that query my database and create original tree.
I have created a Xaml treeView UserControl to bind my root XNode created.
Via Xaml is not possible to hide a Node, this operation must be done with binded object (my root Xnode created).
Now my question is: There are recursive alghoritms to cancel a "Folder type" node, get its childrens and add them to parent Node?
I'm try:
public XNode RemoveFoldersElements(ref XNode rootNode)
{
if (rootNode != null)
{
if (rootNode.Children.Count > 0)
{
for (int i = 0; i < rootNode.Children.Count; i++)
{
XNode children = rootNode.Children.ElementAt(i);
if (children.WType == NodeType.Type_FOLDER)
{
XNode tempNode = RemoveFoldersElements(ref children);
if (tempNode != null)
rootNode.Children.Add(tempNode);
rootNode.Children.RemoveAt(i);
}
else
{
RemoveFoldersElements(ref children);
}
}
}
}
return null;
}
but not success because not all nodes of Type_FOLDER are erased (it jump one level) ! Any Idea?