same problem with treeview
private CTreeNode GetParentNode(CTreeNode node)
{
CTreeNode cTreeNode;
TreeNode[] nodes = this.treeview.Nodes.Find(node.Name, true);
if (nodes[0].Parent == null)
cTreeNode = nodes[0] as CTreeNode;
else
{
cTreeNode = nodes[0].Parent as CTreeNode;
CTreeNode.Nodes.Clear();
cTreeNode.Nodes.Add(nodes[0] as CTreeNode);
this.GetParentNode(cTreeNode);
}
return cTreeNode;
}
this is the function which is designed to get the node like (if a contains b and c and b contains d and e,
a--b--d
--e
--c
if d is passed to this function a node will returns which is a but a has b and b has d
a--b--d
).
but when i pass d to this function only b node is returned.
when i debugged and see, the line switches 开发者_运维技巧between return function and this.GetParentNode(customTreeNode);
i dono why, i think i m missing some basics
can i know why..
Sounds like you are trying to build a node path
CTreeNode[] nodes = this.treeview.Nodes.Find(node.Name, true);
List<CTreeNode> nodepath = new List<CTreeNode>();
GetNodePath(nodes[0], nodepath);
private void GetNodePath(CTreeNode node, List<CTreeNode> nodepath) {
nodepath.Add(node);
if (node.Parent != null) {
GetNodePath(node.Parent, nodepath);
}
}
EDIT
Corrected code
精彩评论