6 Replies - 10682 Views - Last Post: 15 June 2008 - 05:47 PM Rate Topic: -----

#1 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 35
  • View blog
  • Posts: 1,103
  • Joined: 05-June 08

Open files from List box

Posted 14 June 2008 - 10:22 PM

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?

Is This A Good Question/Topic? 0
  • +

Replies To: Open files from List box

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9197
  • View blog
  • Posts: 34,551
  • Joined: 12-June 08

Re: Open files from List box

Posted 15 June 2008 - 08:56 AM

View PostDamage, 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?


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'.
Was This Post Helpful? 0
  • +
  • -

#3 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

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. :)
Was This Post Helpful? 0
  • +
  • -

#4 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

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:
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).
Was This Post Helpful? 0
  • +
  • -

#5 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 35
  • View blog
  • Posts: 1,103
  • Joined: 05-June 08

Re: Open files from List box

Posted 15 June 2008 - 03:51 PM

View Postmodi123_1, on 15 Jun, 2008 - 08:56 AM, said:

View PostDamage, 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?


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 :)

View Postjacobjordan, 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:
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
Was This Post Helpful? 0
  • +
  • -

#6 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

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

Was This Post Helpful? 0
  • +
  • -

#7 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 35
  • View blog
  • Posts: 1,103
  • Joined: 05-June 08

Re: Open files from List box

Posted 15 June 2008 - 05:47 PM

View Postjacobjordan, 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.
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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1