private void SetPath(String path) { HTreeNode current_node = FolderTree.SelectedNode; String current_path = ""; if (current_node != null) { current_path = getPathFromNode(current_node); } //daca pathul este valid si diferit de ce e deja selectat, //construieste calea catre el if (Directory.Exists(path) && !path.Equals(current_path)) { FolderTree.CollapseAll(); //get drive first //TODO: check if in windows it's working String drive = path.Substring(0, path.IndexOf(separator) + 1); //then the rest of the path path = path.Substring(path.IndexOf(separator) + 1); String[] path_parts = path.Split(separator); List <String> parts = new List <String>(); parts.Add(drive); parts.AddRange(path_parts); NodeCollection nodes = FolderTree.Nodes; for (int i = 0; i < parts.Count; i++) { String node_text = parts[i]; //search the node with that text HTreeNode node = null; foreach (HTreeNode n in nodes) { if (!n.Text.Equals(node_text)) { continue; } node = n; break; } //clear nodes childs node.Nodes.Clear(); //build node childs buildNode(node); //expand node FolderTree.expandNode(node); nodes = node.Nodes; } } }