 |
|
 |
i am really wondering how did you load or put those XP icons to the imagelist? I tried to load those ico directly from imagelist properties, but when i run the code, those icons look ugly (outline) whereas when i run your code, icons look just perfect.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I did nothing special at the time, I just added the icons as you did. However, at that time I was using Visual Studio 2002 (I think that was .NET Framework 1.0).
I duplicated your problem by opening the project and converting it to Visual Studio 2008. I was able to fix the problem by fiddling with the imagelist properties.
Try this:
Modify the properties of ImageList:
ColorDepth = Depth32Bit
If that doesn't work, try changing:
ImageSize = 32
If this doesn't solve your problems, I suggest that you do some googling for treeview and imagelist icon problems. Many people have been complaining about this exact problem. The problem was not a problem in 2002, but now it is, so Microsoft obviously changing some things in imagelist.
Russ.
Russell Mangel Las Vegas, NV
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi
Thanks for your code. This is really helpful. But is there any way to cloning the windows explorer. I mean to say The listview which can show the windows context menu on reght clicking on any file or folder. I am not talking about any custom context menu. But the same as windows context menu by useing any Win32API or Shell32API?
Debashis Pal Wipro Technologies
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
Your way of getting the drives was all wrong...you just assumed that the floppy drive would be A, and the fixed ones would be C,D, therefor it showed a floppy drive named A in your program even though i don't even have one.
you can use the DriveInfo class in order to get the drive type.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thanks for the comments.
When I wrote this code back in 2002 (wow it's been 5 years), for .NET version 1.0 there was no pure c# way to get drive types except for using wmi namespace and wmi is really slow, so I just hard-coded them.
I really should post a new version for .NET 2.0. As you mentioned there is a new DriveInfo class in .NET 2.0 that does have drive type enumeration.
Faster performance for getting Files and Directories.
When dealing with directories that have hundreds of thousands of files, it is more efficient to get the files and directories in one pass, you can use FileSystemInfo class for this. However, when calling the attributes property (to determine if the object is a file or folder), then performance is terrible.
For extreme File and Directory performance, use pinvoke and the FindFirstFile or(FindFirstFileEx) WinAPI method.
Have a good day.
Russ
Russell Mangel Las Vegas, NV
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hello. I am a new member here. I am a student learning C#. I have gotten alot out of this demo. However, I do have a question. I have changed the case structure to check the drive type. However, now the drive letter is gone. Can anyone tell me a good way to use the driveType enumeration and still maintain the drive letter in the treeview. Thanks!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Just like to say this is one of the best examples I have seen.
Its easy to work out exactly what is going on and shows the power of .NET, brilliant.
It would be nice if you could produce the rest of the series
Regards
Tom
UK - (Liverpool F C Rule)
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Thanks for the kind comments, I wrote this code many years ago.
A couple of things: 1. Don't try to put 150,000 files in the listview, try to keep the number of items to less than 10,000 rows. If you need to put large amounts of files, you should use a different control like the dataGridView (.Net 2.0). Or better yet, use the DevExpress GridControl (it does sorting). However this grid is not free.
2. If you need to sort on all the columns, you will have to implement your own sorting, there are a few examples around (including one from microsoft). But they are *super* slow , so once again if you need this type of functionality, it is much easier to use a data grid control.
3. The ListView is a nice control, when your application needs a simple list.
Russell Mangel Las Vegas, NV
Russell Mangel Las Vegas, NV
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
 |
I tried this app on our network and found that it doesn't seem to sort the directory names. I looked at the DirectoryInfo docs and it doesn't state the order in which directories are retrieved or if there is a method to sort the directories. Do you know how to make it pull in alpha order?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi
thanx for this nice code, im a beginenr and it helps alot to understand,
but i dont understand why showplusminus = true doeasnt shows the plus and minus always, it first shows them when i click on a node, how to fix that?
bye
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
 |
Simple, but elegant. I like that - it appeals to the engineer in me. When will you be finishing the "series?"
"Please don't put cigarette butts in the urinal. It makes them soggy and hard to light" - Sign in a Bullhead City, AZ Restroom
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thanks for the comment. I was a novice .neter back when I wrote this code, I was hell bent on finding the fastest performance, I must have spent 3-4 months fiddling with treeview control source code, I studied everyone's code and used idea's from all of them.
I was going to post another Inherited "TreeNode" version of Windows Explorer in C#. Even today, when I use the treeview control, I almost always use a derived TreeNode, and then add properties to the node.
I didn't get much response on Windows Explorer in C#. So I don't know if I will post the inherited version or not.
If you are interested leave your email address, I could email you the source code.
Russell Mangel Las Vegas, NV
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Russell Mangel wrote: I was going to post another Inherited "TreeNode" version of Windows Explorer in C#. Even today, when I use the treeview control, I almost always use a derived TreeNode, and then add properties to the node.
I would be intereset on looking at this example 
Nice tutorial, filled my needs.
Jonathan de Halleux. www.pelikhan.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I would also like to see the TreeNode version posted next to this one.
Very good example of PURE .NET code. Not like the DllImport versions.
Very Nice...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
First of all I would like to say that I like your explorer solution. It's pretty much written in pure .NET, without any usage of underlying interop, which is still everybodies habit in these early days. However, it seems that with .NET sometimes we just can't escape from 'reaching back to the old technology'. There is a problem with your accessment of logical drives. You assume that C:\ drive is fixed drive and A:\ drive is removable drive. It's highly likely that it is the case, but you can't be sure. Those logical drives need to be tested for their types:
[DllImport("kernel32.dll")] public static extern long GetDriveType(string driveLetter);
private void Form_Load(object sender, System.EventArgs e) { string[] aDrives = Environment.GetLogicalDrives(); treeView1.BeginUpdate(); foreach(string strDrive in aDrives) { TreeNode dnMyDrives = new TreeNode(strDrive.Remove(2,1)); dnMyDrives.SelectedImageIndex = (int) GetDriveType(strDrive); dnMyDrives.ImageIndex = (int) GetDriveType(strDrive); } treeView1.EndUpdate(); }
This assumes that image list indices are in accordance with the GetDriveType return values. Regards,
Dejan Petrovic
|
| Sign In·View Thread·PermaLink | 3.00/5 (1 vote) |
|
|
|
 |
|
 |
Thanks for the comment. You are correct about the C:\ drive and A:\ drive, the example was designed to be simple, and I didn't think it appropriate to add PInvoke code to such a simple example. The Icons would also be incorrect if the drive letters were not typical.
You could also use WMI code to get the drive types, it's a little slower than PInvoke, but it is pure .NET code.
Russell Mangel Las Vegas, NV
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You could also use a VBScript Interop providing this.
Then you could use the FileSystemObject and call its GetDriveType method.
---- xasx
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
 |
When I use USB Flash Disk, your program use the same image in image list to display both Floppy Disk and USB Flash Disk.I want they have diffrent image. How can I do?
|
| Sign In·View Thread·PermaLink | 3.00/5 (1 vote) |
|
|
|
 |
|
 |
In the foreach loop you forgot to add the new node you are creating to the tree view...
string[] aDrives = Environment.GetLogicalDrives(); treeView1.BeginUpdate(); foreach (string strDrive in aDrives) { TreeNode dnMyDrives = new TreeNode(strDrive.Remove(2, 1)); dnMyDrives.SelectedImageIndex = (int)GetDriveType(strDrive); dnMyDrives.ImageIndex = (int)GetDriveType(strDrive);
treeView1.Nodes.Add(dnMyDrives); // <-- Need This line added! } treeView1.EndUpdate();
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
If you're using .NET 2.0, you can use the System.IO.DriveInfo to get a list of all available drives. It contains a DriveType so that you can loop through the available drives and can assign a icon accordingly.
using System.IO; --------------------
DriveInfo[] AvailableDrives = DriveInfo.GetDrives(); int numOfDrives = AvailableDrives.Length;
----------------
then loop appropriately. AvailableDrives[ArrayCount].name contains the drive name. while AvailableDrives[ArrayCount].DriveType contains the DriveInfo.DriveType.CDRom or .FixedDisk needed to compare.
--rob
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |