Results 1 to 11 of 11

Thread: [RESOLVED] Double Click

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Resolved [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.

  2. #2
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    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."

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    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?

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Double Click

    works fine with a double click

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub DisplayFileName()
    4.         Dim fileName As String = Nothing
    5.  
    6.         Using ofd As New OpenFileDialog
    7.             Dim result As DialogResult = ofd.ShowDialog
    8.  
    9.             If result = System.Windows.Forms.DialogResult.OK Then
    10.                 fileName = ofd.FileName
    11.             End If
    12.         End Using
    13.  
    14.         If fileName IsNot Nothing Then
    15.             MessageBox.Show(fileName)
    16.         End If
    17.     End Sub
    18.  
    19. End Class
    My Github - 1d3nt

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    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.

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: [RESOLVED] Double Click

    So help other members by posting what you was doing wrong and what solved it.
    My Github - 1d3nt

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    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.

  8. #8
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: [RESOLVED] Double Click

    If you want to run a file then use process start
    My Github - 1d3nt

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    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)

  10. #10
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: [RESOLVED] Double Click

    I have no idea what you are trying to say to me.
    My Github - 1d3nt

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    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
  •  



Click Here to Expand Forum to Full Width