|
-
Mar 6th, 2015, 04:31 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Double Click
I have a form that uses an OpenFileDialog to open a windows browser to a specified directory. Now I can open the files contained in the directory by right clicking them and selecting open. However, for whatever reason, it will not open a file by double clicking on the file, but instead just closes the window. Whenever I use this same type of window from the native Windows system the double click always works for me. Is it possible for anyone to explain this behavior to me i.e. why does the double click not work from the Visual Basic OFD but does in the Windows environment?
By the way, all the files contained in the directory are either Word, Excel, Adobe PDF, zip, Visio, and a few others I cannot remember right now.
Below is the code used to call the OFD. the variable txtMasterFiles contains the filepath and directories to be open.
ofdFileCabinet.InitialDirectory = txtMasterFiles
ofdFileCabinet.ShowDialog()
Last edited by gwboolean; Mar 6th, 2015 at 04:34 PM.
-
Mar 6th, 2015, 04:55 PM
#2
Re: Double Click
You have to do something with that file (actually, you will receive a file name).
By right-clicking, and selecting open,the control is invoking the base windows operating system shell command to open the specific file. This has nothing to do with your application. Indeed, you can browse for a file in word, right-click a pdf document, and the pdf file handler will open up the associated file.
"Ok, my response to that is pending a Google search" - Bucky Katt.
"There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
"Before you can 'think outside the box' you need to understand where the box is."
-
Mar 6th, 2015, 05:05 PM
#3
Thread Starter
Fanatic Member
Re: Double Click
I understand that and that is exactly what I have been doing. It works fine that way, but I know that I can double-click a file when using the same window browser from the windows operating system. So why won't the double-click work when using this browser window from Visual basic?
-
Mar 6th, 2015, 05:22 PM
#4
Re: Double Click
works fine with a double click
vb Code:
Public Class Form1 Private Sub DisplayFileName() Dim fileName As String = Nothing Using ofd As New OpenFileDialog Dim result As DialogResult = ofd.ShowDialog If result = System.Windows.Forms.DialogResult.OK Then fileName = ofd.FileName End If End Using If fileName IsNot Nothing Then MessageBox.Show(fileName) End If End Sub End Class
-
Mar 6th, 2015, 05:37 PM
#5
Thread Starter
Fanatic Member
Re: Double Click
Thanks. What's really cool is that am must be starting to get good with Visual Basic as I can actually read your code and understand what it is doing and how it works. Life is goooooood.
-
Mar 6th, 2015, 05:48 PM
#6
Re: [RESOLVED] Double Click
So help other members by posting what you was doing wrong and what solved it.
-
Mar 6th, 2015, 05:54 PM
#7
Thread Starter
Fanatic Member
Re: [RESOLVED] Double Click
I wasn't doing anything wrong. And while your code works and I can understand it, I still have no idea why the extra code is necessary to make the browser open/execute a file on a double-click or using the open button when the window is opened from Visual Basic. That is still way beyond my pay grade.
-
Mar 6th, 2015, 06:02 PM
#8
Re: [RESOLVED] Double Click
If you want to run a file then use process start
-
Mar 6th, 2015, 06:17 PM
#9
Thread Starter
Fanatic Member
Re: [RESOLVED] Double Click
I have been using the following to first create a directory:
'creates Directory for files
System.IO.Directory.CreateDirectory(FILEPATH & txtFileAdd)
Then I use the OFD to open the directory:
ofdFileCabinet.InitialDirectory = txtMasterFiles
ofdFileCabinet.ShowDialog()
Then, from the browser window, I can scan files into the directory or copy/move them into the directory. Additionally, the files can be opened by selecting the file and right clicking. As soon as I can find some time to put in the code you gave me I should also be able to open the selected file with a double-click.
One other thing Is I can run a application by doing the following (in this case Adobe Acrobat which I use to scan documents into the directory):
'Opens Adobe Acrobat 11.0
Diagnostics.Process.Start(ADOBEPATH)
-
Mar 6th, 2015, 06:19 PM
#10
Re: [RESOLVED] Double Click
I have no idea what you are trying to say to me.
-
Mar 6th, 2015, 06:22 PM
#11
Thread Starter
Fanatic Member
Re: [RESOLVED] Double Click
So sorry. I thought I was speaking English. At any rate, thanks for the code, it will help with a minor problem that bothered me.
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
|