Good Day All.
Am binding the treeview from a Database and it gets populated and am sorting it after this way
SortTree(CurriculumTreeView);
private void SortTree(TreeView tv)
{
if (tv.Nodes != null)
{
for (int i = 0; i < tv.Nodes.Count; i++)
{
TreeNode node = tv.Nodes[i];
SortNode(node);
}
}
}
private void SortNode(TreeNode node)
{
if (node.ChildNodes != null && node.ChildNodes.Count > 1)
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
TreeNode childNode = node.ChildNodes[i];
SortNode(childNode);
SortNodes(node.ChildNodes);
}
}
}
private void SortNodes(TreeNodeCollection nodes)
{
if (nodes == null || nodes.Count < 2)
{
return;
}
for (int i = 0; i < nodes.Count - 1; i++)
{
for (int j = 0; j < nodes.Count - 1; j++)
{
TreeNode node = nodes[j];
TreeNode nextNode = nodes[j + 1];
if (node.Text.CompareTo(nextNode.Text) > 0)
{
TreeNode tempNode = new TreeNode();
tempNode = nextNode;
nodes.Remove(nextNode);
nodes.AddAt(i, tempNode);
}
}
}
}
when i don't sort, everything is faster, but now with this sorting its very slow and end up timing out.
Thanks