Is it something like Windows Commander? Great deal, but then you will face more difficult problems then the one you just asked.
Can we use a specific fact the the tree views represent the file system?
My advice is to use the file structure itself as a source of information for another tree. Let's assume you already have the code that populate the tree based on some point in the file system tree. So you have two tree views and two "real" trees representing the points in the directory structure.
You code should be universal. If not, it should be done a bit more universal. This must be a method that expects the following arguments: current tree node (target node) and (source) point in the directory structure (a file or directory name); additionally, you may want to pass one more, boolean argument to tell the file name from directory name. For simplicity, let's only talk about directories.
You should already have this method, or almost this. If it only works for an empty tree, it can be generalized to be applied to arbitrary branch of a populated tree.
Now, you use one tree as a source. But instead or traversing this tree, we only take the selected node. Every node should know corresponding directory. You read this directory and pass as the source node to the function I just described. From this moment, forget about source tree: use only directory structure. The function should traverse directory structure recursively from the source point and reproduce all the actions you already done populating your tree.
This is just the idea. Further detail require discussion of your design detail; and you did not provide a single line of code.
Another advice is the type you store in a tree node. It should be a full path (maybe, some (cashed) attributes). Probably you need only a simple name (not a path name). What to do? You should make a type which hold full path name but the tree shows only a simple name. Here is how: you wrap the name in a structure and override
ToString()
:
internal struct TreeNodeHelper {
public override void ToString() {
return System.IO.Path.GetFileName(PathName);
}
internal string PathName;
internal bool IsDirectory;
}
This type will appear in the tree view as a string with a simple name, but for your operations you will have full information. Same applied to list boxes.
I think you should have an idea. The bigger problem is doing actual file operations (again, if this is a file manager). It will involve merger in the file system, resolving name clashes (replace? ignore?), locked files, etc. And will you process also the hard links and soft links (reparse points) like in Unix? Windows does support POSIX, so you will need all that. This is your own problem for now, anyway.
Sorry if I answered not exactly your question, but you should have provided more detailed and accurate description. You can ask further questions, anyway.
Thank you.