The following code will sort TreeNodeCollection on text basis:
private TreeNodeCollection SortTreeNode(TreeNodeCollection nodeList)
{
for (int i = 0; i < nodeList.Count-1; i++)
{
for (int j = i + 1; j < nodeList.Count; j++)
{
if (nodeList[i].Text.CompareTo(nodeList[j].Text)>0)
{
TreeNode temp = nodeList[i];
nodeList.RemoveAt(i);
nodeList.AddAt(i,nodeList[j-1]);
nodeList.RemoveAt(j);
nodeList.AddAt(j, temp);
}
}
}
return nodeList;
}
No comments:
Post a Comment