 |
|
 |
What if I want to load system folders in the treeview such as MyComputer, MyNetwork etc..??
|
|
|
|
 |
|
 |
Good job first of all, but how come I can't get the full path. I returns the name of the folder only?
filePath = tv.SelectedNode.FullPath.ToString();
|
|
|
|
 |
|
 |
Really great work! I compiled it on VS 2005.NET on Framework .NET 2.0 and executed it on Windows 2003 Server SE. It works perfectly, except that some of the icons appear with black background, for example DLL and TXT icons. I found some article describing how to convert some color to transparent color:
http://ewbi.blogs.com/develops/2005/08/sparklines_22.html[^]
But it converts ALL the color pixels into transparent ones. Do you have any idea how can we get an icon from the OS with transparent background instead of black?
|
|
|
|
 |
|
 |
Hi Boris,
you just have to set the ColorDepth of the image list.
Code:
ImageList imgList = new ImageList();
imgList.ColorDepth = ColorDepth.Depth32Bit;
After this the icons will be displayed correctly without the black background.
Hope that this will help you.
Best regards
Assaad
|
|
|
|
 |
|
 |
i have made some changes to use the treeview to open the selectedfile in to a axwebbrowser but not only the selected files opens into the browser olso the directory but that is not wat i want.(I use the selectedNode).
i want to load only the selected files (*.html or *.txt not the c:\\ ) not the directory in to the browser .
the next problem that comes up is when i use the open button to load another directory place in to the treeview then i can not use the selectednode or selectedfile for the webbrowser its not recognizing the path .
I whant to use webbrowser is to open the *.html documents becouse the richtextbox does not support images like *html.
thanx for jour help .
more people more fun
|
|
|
|
 |
|
 |
hi
how can i use the treeview to open files when i dubbelclick ont it
i realy want to use the tree without listview so to doe that i want to use a textbox or richtextbox to open the selected (node)file ..
i can't access the textbox from your class becouse iam a beginner.
sorry for my english.
please help.
more people more fun
|
|
|
|
 |
|
 |
Add this property to the FileNode class
public string Filename
{
get{ return _fileInfo.FullName;}
}
Create an event handler for the DoubleClick event of the FileSystemTreeView. Then inside the event you can get a handle to the selected node.
void tree_DoubleClick(object sender, EventArgs e)
{
if (tree.SelectedNode == null) return;
if( tree.SelectedNode.GetType() == typeof(FileNode) ) {
System.Diagnostics.Process.Start(((FileNode)tree.SelectedNode).Filename);
}
}
Note: this code only handles nodes that are of type 'FileNode' you should probably add an else statement for the DirectoryNode class.
|
|
|
|
 |
|
 |
Good work first off
I needed to return the filename/foldername of the node selected so I added the following
The start of the class FileSystemTreeView now looks like this
public delegate void MyEventHandler(object sender, MyEventArgs me);
public class FileSystemTreeView : TreeView
{
public event MyEventHandler MyEvent;
private bool _showFiles = true;
private ImageList _imageList = new ImageList();
private Hashtable _systemIcons = new Hashtable();
private string fs = ""; // File/Folder selected
and in the mousedown event I added
this.SelectedNode = node; //select the node under the mouse
fs = node.Text;
if (MyEvent != null)
MyEvent(this, new MyEventArgs(this.fs));
then the class MyEventArgs was added to the namespace C2C.FileSystem
public class MyEventArgs : System.EventArgs
{
public string fs;
public MyEventArgs(string val) : base()
{
this.fs = val;
}
}
Finally in the main form load method I added the line & following method
(fns was a simple new label on the form to show the returned filename/folder)
tree.MyEvent += new MyEventHandler(tree_MyEvent);
private void tree_MyEvent(object sender, MyEventArgs me)
{
fns.Text = me.fs;
}
Again, thanks...
Jim
|
|
|
|
 |
|
 |
does not work for me gives me error on this line
public delegate void MyEventHandler(object sender, MyEventArgs me);
can't find MyEventArgs me ??? is it a Dll or???
more people more fun
|
|
|
|
 |
|
 |
Just what I was looking for, well more or less. I was looking for a file system browser and liked the idea that it loads nodes on demand to improve performance.
It was however missing something I also needed: to be able to select multiple nodes, not just one as in the standard tree view. Previous to this I had found a project that implemented just that. So I merged those changes into this project, added some extra comments, some design-time properties and now I could use it in solving my problem at hand.
Thanks a Lot! Good work!
|
|
|
|
 |
|
 |
Doesn't Compile which makes following snipet code useless as a coding example.
I'm using 2003 .Net so tree.ShowFiles = false; bombs as does tree.Load?
I was hoping I could find an example of how to use .expand() in treeview.
I want my directory refresh to remember what nodes a user had expanded.
-t-
|
|
|
|
 |
|
 |
I am trying to figure out how to best add a search filter to the tree. Should I modify the control or make changes to the tree after the fact. I have tried additional overloading methods with out much success.
Any hints?
Thanks!
|
|
|
|
 |
|
 |
I made it this way.
On the FileSystemTreeView class I added this variable:
private string _searchPattern;
on the FileSystemTreeView_BeforeExpand I replaced:
if (this._showFiles == true)
{
node.LoadFiles();
}
for:
if (this._showFiles == true)
{
if (string.IsNullOrEmpty(_extension))
node.LoadFiles();
else
node.LoadFiles(_searchPattern);
}
and added a Property setter and getter
and on the DirectoryNode class I added this method:
public void LoadFiles(string searchPattern)
{
foreach (FileInfo file in _directoryInfo.GetFiles(searchPattern))
new FileNode(this, file);
}
|
|
|
|
 |
|
 |
Michael,
Thanks so much for the article! I was trying to modify it to have it delete all directory node elemenst on each expand by iterating thru the nodes and removing them prior to population, but had many remained. I want to do this to capture any files added behing the scenes after expansion. I was using node.Nodes[i].remove, but it left namy nodes??
Can you offer a suggestion? Also, if anyone has extended this I would love to see the code.
Best regards,
mike
Mike
|
|
|
|
 |
|
 |
Hello
How would you get files, with a folder to open in it's associated app when a file is double clicked? For instance, if you browse to folder c:\xyz which contains text files, how do you have them open in notepad?
Thanks
J
|
|
|
|
 |
|
 |
This should open the file with the associated application.
System.Diagnostics.Process.Start(@node.FullPath);
|
|
|
|
 |
|
 |
Hello
Perhaps that will open files, however as a newbie where/how do I use it?
Thank You
J
|
|
|
|
 |
|
 |
double click on the tree control in your design view.
A new event handler will be created.
Paste the code in that eventhandler (method)
|
|
|
|
 |
|
 |
hi michael, im making an extended version of your exellent class.
it supports drag and drop
I am having a problem making a new FileNode object and adding it to its' parent, i hope you can help me.
What i have is this....
private void MoveFile(TreeNode Node1, TreeNode Node2) //source,destination
{
string strdir1 = Node1.Parent.FullPath; // get the path of the source item
string strdir2 = Node2.FullPath; // get the path of the drop target
strdir1 = strdir1 + "\\" + Node1.Text; // create file paths using the name
strdir2 = strdir2 + "\\" + Node1.Text;
Directory.Move(strdir1, strdir2); // use the static Directory Move co
DirectoryInfo dir = new DirectoryInfo(Node2.FullPath);
DirectoryNode dirnode = new DirectoryNode((DirectoryNode)Node2.Parent,dir);
FileInfo finfo = new FileInfo(strdir2);
FileNode aNode = new FileNode(dirnode,finfo); // create a new file node
Node1.Remove(); // remove the old file node
Node2.Nodes.Add(aNode);
}
|
|
|
|
 |
|
 |
The constructor of the DirectoryNode class is actually responsible for adding a node to the tree.
public DirectoryNode( DirectoryNode parent, DirectoryInfo directoryInfo ) : base( directoryInfo.Name )
{
this._directoryInfo = directoryInfo;
this.ImageIndex = FileSystemTreeView.Folder;
this.SelectedImageIndex = this.ImageIndex;
parent.Nodes.Add( this );
Virtualize();
}
You should create a new DirectoryNode object and then pass its parent node as an argument. If you follow the variable names in your
code snippet you will end up with the following code:
new DirectoryNode( Node2, finfo );
Hope this clarified things for you. Let me know if you have any other questions.
|
|
|
|
 |
|
 |
Hi that kinda worked, but the directory would be moved, which is not so good. however i came up with another idea. and it works as long as there is less than 4 items in the destination node. Whenever the destination node contains 4 or more items, it crashes.. can you see why??
What it does is delete all the nodes in the destination node, and then load them again, to avoid duplicates of the items.
private void MoveFile(FileNode Node1, TreeNode Node2)
{
string strdir1 = Node1.Parent.FullPath; // get the path of the
string strdir2 = Node2.FullPath; // get the the drop target
strdir1 = strdir1 + "\\" + Node1.Text; // create file paths strdir2 = strdir2 + "\\" + Node1.Text;
Directory.Move(strdir1, strdir2); // use the
DirectoryNode dirnode = (DirectoryNode)Node2;
foreach(TreeNode node in dirnode.Nodes)
node.Remove();
dirnode.LoadFiles();
dirnode.LoadDirectory();
Node1.Remove();
}
|
|
|
|
 |
|
 |
The only problem with
new DirectoryNode( Node2, finfo );
is that it will add the directory node and the correct file at the bottom of sub-tree.
It should add the directory on the same location as it was before
|
|
|
|
 |
|
 |
hey I fixed it by making a new constructor for the directorynode that takes the index to input the node at
it now supports drag and drop
|
|
|
|
 |
|
 |
Greetings,
I was wondering if you might post your modifications, as i would like to see them.
Best Regards,
mike
Mike
|
|
|
|
 |
|
 |
A solution file would have been great... so I could easily test it out and see if this was what I was looking for.
|
|
|
|
 |