Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using two treeview controls. In first treeview I added some folders and files. But now I want to write a code for whatever I selected the folders or files of first treeview control, that folders or files should be sent to second treeview control, whenever I click the send button.

Please help me.
Thank you.
Posted
Updated 5-Jan-11 20:51pm
v2
Comments
Sergey Alexandrovich Kryukov 6-Jan-11 3:15am    
I don't see a problem. If you already have a code that populates some branch of the tree view, you can also repeat that for another instance of a tree view, can't you?
Sandeep Mewara 6-Jan-11 3:16am    
Ok. So did you try anything? Tree node click event?
Sergey Alexandrovich Kryukov 6-Jan-11 3:42am    
No, Sandeep, it has nothing to do with node click. Node is only marked by selection.

1 solution

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():

C#
internal struct TreeNodeHelper {
    //...
    public override void ToString() {
        return System.IO.Path.GetFileName(PathName);
    } //ToString
    //...
    internal string PathName;
    internal bool IsDirectory; //SA???
} //struct TreeNodeHelper


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.
 
Share this answer
 
v2
Comments
Dalek Dave 6-Jan-11 3:42am    
Very Good Answer.
Sergey Alexandrovich Kryukov 6-Jan-11 3:49am    
Thank you Dalek. There is essential update about POSIX features (imagine a challenge for such a beginner :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900