private static bool FirstComesBeforeSecond(TreeNode first, TreeNode second) { bool isFirstDirectory = first.IsComponentsFolderTreeNode() || first.IsScreensFolderTreeNode(); bool isSecondDirectory = second.IsComponentsFolderTreeNode() || second.IsScreensFolderTreeNode(); if (isFirstDirectory && !isSecondDirectory) { return true; } else if (!isFirstDirectory && isSecondDirectory) { return false; } else { return first.Text.CompareTo(second.Text) < 0; } }