Yash35 wrote:
m_oTree.Nodes.Find(oNode.ParentKey, true)[0].Nodes.Add(oNode.Key, oNode.DisplayText, ReturnImageListIndex(oNode), ReturnImageListIndex(oNode));
i am adding nodes to treeview with above line of code.
it is windows forms. I want it to be last descendant of its parent node i.e root node.
My tree has a single root node
In the WinForm Microsoft TreeView there is no .ParentKey property of a TreeNode, and someNode.Parent.Key would be an error, also.
While it is possible you have sub-classed TreeNode, and added a 'ParentKey field ... I doubt that.
If you have a single root node in your design, then why not keep a pointer to the Nodes Collection of the root node; then, you can be certain that if you use 'Add on that collection, the TreeNode you add will be the last TreeNode in the TreeView
private TreeNodeCollection rootNodes;
private void YourForm_Load(object sender, EventArgs e)
{
rootNodes = yourTreeView.Nodes;
}
private void someAddTreeNodeMethod(string nodeText)
{
rootNodes.Add(new TreeNode(nodeText));
}