|
-
Oct 7th, 2012, 09:23 AM
#8
Re: ExplorerTreeView
Whenever you have a Control that isn't behaving as you expect it to, you should always check the documents for that Control.
If you look at the documents for the TreeView Control and scroll right on down to the Remarks section you will see that it has a SelectedImageIndex property as well as an ImageIndex property (not to mention the ImageKey and SelectedImageKey properties).
Note that the same is also true for TreeNodes.
If you read up on those properties you will see that (from http://msdn.microsoft.com/en-us/libr...vs.100%29.aspx )
 Originally Posted by MSDN
The ImageKey and ImageIndex properties are mutually exclusive; therefore, if one property is set, the other is ignored. If you set the ImageKey property, the ImageIndex property is automatically set to -1. Alternatively, if you set ImageIndex, ImageKey is automatically set to an empty string ("").
so the line
Code:
If e.Node.ImageKey = "folder" Then Exit Sub
in your TreeView2_NodeMouseDoubleClick sub won't be working as expected since you use the ImageIndex property to assign your images to the Nodes.
This is the reason that the DoubleClick on a Node is opening its Folder. The above check is failing. You need a better way of determining if a Node is representing a Folder or a File.
One way might be to check if ImageIndex = 0 or even just check if the file exists before trying to run it.
vb.net Code:
Private Sub TreeView2_NodeMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView2.NodeMouseDoubleClick
' only proceed if the node represents a file
Try
If File.Exists(e.Node.Tag.ToString) Then
Process.Start(e.Node.Tag.ToString)
End If
Catch ex As Exception
MessageBox.Show("Error opening file: " & ex.Message)
End Try
End Sub
As to your Click event handler code; from what you've said so far, it doesn't look like you actually need this, but only you know what else you might want your program to do. It seems to be the exact same code as your TreeView2_BeforeExpand handler code. That code creates nodes for displaying the contents of a Folder. It gets info about the Folder's contents by creating an instance of the DirectoryInfo Class for the Folder. However, in the Click event handler code you are not differentiating between clicking on a File or clicking on a Folder. The code tries to create a DirectoryInfo instance for the File represented by the Node you click on, which clearly can't work. Check if the Node clicked upon represents a File or a Folder and don't execute the code if it's a File.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|