Heya, i've got a list box that contains the full path of a file(i've got an app that allows the user to search for files,drilling as far down as being able to search for files containing certain text, basically my own windows search function). My question is, is it possible to code an event in the list box that would open the file?
Like the user searches for a text document and then double clicks on the item in the list box and it opens?
Open files from List box
Page 1 of 16 Replies - 13547 Views - Last Post: 15 June 2008 - 05:47 PM
Replies To: Open files from List box
#2
Re: Open files from List box
Posted 15 June 2008 - 08:56 AM
Damage, on 15 Jun, 2008 - 12:22 AM, said:
Heya, i've got a list box that contains the full path of a file(i've got an app that allows the user to search for files,drilling as far down as being able to search for files containing certain text, basically my own windows search function). My question is, is it possible to code an event in the list box that would open the file?
Like the user searches for a text document and then double clicks on the item in the list box and it opens?
Like the user searches for a text document and then double clicks on the item in the list box and it opens?
Yes it is possible.. I am not sure if there is a double click event persay but there is a 'selected index changed' event that is what you are looking for. It's in the drop down for the events. I would advise against using 'selected value changed' since I don't believe that will get what you want.
Side question, if you are doing some sort of drill down, why are you not using a tree? The whole parent/child node setup better represents a 'drill down'.
#3
Re: Open files from List box
Posted 15 June 2008 - 09:29 AM
Quote
I am not sure if there is a double click event persay
Yes, there is.

#4
Re: Open files from List box
Posted 15 June 2008 - 12:53 PM
Well, it's possible, but the only way i know of doing it is to access the registry and find what program is associated with the extension of the file you are trying to open. I actually have done something like this before, but it was more limited than what you are talking about. It would probably take me a few hours to code you a function to open a file like your wanting. However, here is a function that will return you the name of the program that the file should be opened with:
There is one drawback, though. The name of the program will be all mixed in with the commands that should be passes to it, so you can't just do Shell(programname). For example, if you did this with ".txt", it would return "C:\WINDOWS\system32\NOTEPAD.EXE %1" (Providing you have an XP machine).
Public Function GetProgram(ByVal extention As String) As String 'extenton is the extention of the file your trying to open (ex, ".txt") Try Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.ClassesRoot.OpenSubKey(My.Computer.Registry.ClassesRoot.OpenSubKey(extention).GetValue("")) Return key.OpenSubKey("Shell").OpenSubKey("Open").OpenSubKey("command").GetValue("") Catch ex As Exception Return String.Empty End Try End Function
There is one drawback, though. The name of the program will be all mixed in with the commands that should be passes to it, so you can't just do Shell(programname). For example, if you did this with ".txt", it would return "C:\WINDOWS\system32\NOTEPAD.EXE %1" (Providing you have an XP machine).
#5
Re: Open files from List box
Posted 15 June 2008 - 03:51 PM
modi123_1, on 15 Jun, 2008 - 08:56 AM, said:
Damage, on 15 Jun, 2008 - 12:22 AM, said:
Heya, i've got a list box that contains the full path of a file(i've got an app that allows the user to search for files,drilling as far down as being able to search for files containing certain text, basically my own windows search function). My question is, is it possible to code an event in the list box that would open the file?
Like the user searches for a text document and then double clicks on the item in the list box and it opens?
Like the user searches for a text document and then double clicks on the item in the list box and it opens?
Yes it is possible.. I am not sure if there is a double click event persay but there is a 'selected index changed' event that is what you are looking for. It's in the drop down for the events. I would advise against using 'selected value changed' since I don't believe that will get what you want.
Side question, if you are doing some sort of drill down, why are you not using a tree? The whole parent/child node setup better represents a 'drill down'.
why am i not using a tree? There's a very good reason why i'm not using a tree. I super new at this and teaching myself,so i had no idea about trees

jacobjordan, on 15 Jun, 2008 - 12:53 PM, said:
Well, it's possible, but the only way i know of doing it is to access the registry and find what program is associated with the extension of the file you are trying to open. I actually have done something like this before, but it was more limited than what you are talking about. It would probably take me a few hours to code you a function to open a file like your wanting. However, here is a function that will return you the name of the program that the file should be opened with:
There is one drawback, though. The name of the program will be all mixed in with the commands that should be passes to it, so you can't just do Shell(programname). For example, if you did this with ".txt", it would return "C:\WINDOWS\system32\NOTEPAD.EXE %1" (Providing you have an XP machine).
Public Function GetProgram(ByVal extention As String) As String 'extenton is the extention of the file your trying to open (ex, ".txt") Try Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.ClassesRoot.OpenSubKey(My.Computer.Registry.ClassesRoot.OpenSubKey(extention).GetValue("")) Return key.OpenSubKey("Shell").OpenSubKey("Open").OpenSubKey("command").GetValue("") Catch ex As Exception Return String.Empty End Try End Function
There is one drawback, though. The name of the program will be all mixed in with the commands that should be passes to it, so you can't just do Shell(programname). For example, if you did this with ".txt", it would return "C:\WINDOWS\system32\NOTEPAD.EXE %1" (Providing you have an XP machine).
thats pretty nifty, thanks man
#6
Re: Open files from List box
Posted 15 June 2008 - 04:10 PM
Ok, well after looking through the piles of my old dusty code, i found a function that should parse the actual file path from the path returned by the function in my previous post.
From my experience, this works with almost all of the possible paths passed to it.
Also, you can use this method to actually open the file in the app:
Function ParsePath(ByVal File As String) As String Dim v2 As String = File If IO.File.Exists(File) Then GoTo skip If InStr(v2, "\\") Then v2 = v2.Replace("\\", "\") End If Try If File.Substring(0, 1) = Chr(34) Then v2 = File.Substring(1) v2 = v2.Substring(0, v2.IndexOf(Chr(34))) Else If InStr(File, " ") Then v2 = File.Substring(0, File.IndexOf(" ")) End If End If Catch End Try If IO.File.Exists(System.Environment.GetEnvironmentVariable("windir") & "\" & v2) Then v2 = System.Environment.GetEnvironmentVariable("windir") & "\" & v2 End If If IO.File.Exists(System.Environment.GetEnvironmentVariable("windir") & "\system32\" & v2) Then v2 = System.Environment.GetEnvironmentVariable("windir") & "\system32\" & v2 End If skip: Return v2 End Function
From my experience, this works with almost all of the possible paths passed to it.
Also, you can use this method to actually open the file in the app:
Public Sub OpenF(ByVal App As String, ByVal File as String) Shell(Chr(34) & App & Chr(34) & " " & Chr(34) & File & Chr(34)) End Sub
This post has been edited by jacobjordan: 15 June 2008 - 04:11 PM
#7
Re: Open files from List box
Posted 15 June 2008 - 05:47 PM
jacobjordan, on 15 Jun, 2008 - 04:10 PM, said:
Ok, well after looking through the piles of my old dusty code, i found a function that should parse the actual file path from the path returned by the function in my previous post.
From my experience, this works with almost all of the possible paths passed to it.
Also, you can use this method to actually open the file in the app:
Function ParsePath(ByVal File As String) As String Dim v2 As String = File If IO.File.Exists(File) Then GoTo skip If InStr(v2, "\\") Then v2 = v2.Replace("\\", "\") End If Try If File.Substring(0, 1) = Chr(34) Then v2 = File.Substring(1) v2 = v2.Substring(0, v2.IndexOf(Chr(34))) Else If InStr(File, " ") Then v2 = File.Substring(0, File.IndexOf(" ")) End If End If Catch End Try If IO.File.Exists(System.Environment.GetEnvironmentVariable("windir") & "\" & v2) Then v2 = System.Environment.GetEnvironmentVariable("windir") & "\" & v2 End If If IO.File.Exists(System.Environment.GetEnvironmentVariable("windir") & "\system32\" & v2) Then v2 = System.Environment.GetEnvironmentVariable("windir") & "\system32\" & v2 End If skip: Return v2 End Function
From my experience, this works with almost all of the possible paths passed to it.
Also, you can use this method to actually open the file in the app:
Public Sub OpenF(ByVal App As String, ByVal File as String) Shell(Chr(34) & App & Chr(34) & " " & Chr(34) & File & Chr(34)) End Sub
wow, sweet, thanks again
Page 1 of 1