所以,这是代码,我希望 treeView1.Nodes 包含 TreeNodes 和 XmlNodes,特别是存储此类对象,如上面的代码所示:
public class Node : TreeNode
{
public XmlNode node{ set; get; }
public Node(XmlNode node):base(){
this.node = node;
base.Text = node.Name;
}
public void delete()
{
node.RemoveAll();
node = null;
base.Remove();
}
}
private void populate(XmlNodeList nodes, TreeNodeCollection tree)
{
if (nodes != null)
{
foreach (XmlNode child in nodes)
{
int index = tree.Add(new Node(child));
if (child.ChildNodes != null)
{
populate(child.ChildNodes, tree[index].Nodes );
}
}
}
}
现在我意识到构造的Node对象仍然存储为TreeNode,我怎样才能使上面的行成为可能?
Node selected = treeView1.SelectedNode;
selected.delete();