I am importing a file into my listbox and I want the second value to open up the actual directory where the file above is located. Is there a way to do this
Files is simply:
nameof-file
File-location
pointers are always appriciated
I am importing a file into my listbox and I want the second value to open up the actual directory where the file above is located. Is there a way to do this
Files is simply:
nameof-file
File-location
pointers are always appriciated
ListBox question
Vjy
Sorry - let me explain more ...
I have a text file that I load into a list box. The text in the list box is 2 lines per per file entry - that is a file name then the next line is the location of the file "G:\directory\directory\" or what ever the associated file location is. This is repeated over and over.
What I want to do is show the file name then the line below to be a button or somehthing so that when you click it either the file will pop up or just the directory - which is I think the best
Some code that I have. nothing fancy - just part of what I am doing
Dim sr As IO.StreamReader = IO.File.OpenText(LOADLOCATION)ListBox1.Items.Clear()
Do While sr.Peek <> -1name = sr.ReadLine
ListBox1.Items.Add(name)
Loopsr.Close()
OUT PUT NOW LOOKS like this
filename1
location1
filename2
location2....
I would like
filename [button for location]
or
[hperlink]filename[end of hyperlink]
this is in a listbox
ghw123
You wil have to be a little more clear on whats going on and what you want to happen...
Is the name of the file the first item in the list box and the directory the second item in the list box
What do you want to happen (open Up) with the directory
If
Directory.Exists("ThePath") Then Dim MyFiles() As String = Directory.GetFiles("ThePath") For Each s As String In MyFiles Me.ListBox1.Items.Add(s) Next End IfDFX1212
Jim Perry
well loading it from a textfile will have a few problems:
however keeping it simple, if our format is:
filename1
location
and we think that the format of the file and entries are the same then we could simply do this....
Dim theReader as new System.IO.StreamReader("file.txt")
while theReader.EndOfStream = false
theReader.ReadLine() 'since firstline is "filename1" rather than the location which is the second line
Me.theListBox.Items.Add(theReader.ReadLine())
end while
theReader.Close()
then we implement a selectedindexchanged event on the listbox so when the user clicks on an entry, it fires the event and you can do whatever you want since the selected item has been changed....so in your example you wanted to launch the path of the item selected
private sub theListBox_SelectedIndexChanged(byval sender a object, byval e as eventargs) handles theListBox.SelectedIndexChanged
if Me.theListBox.SelectedIndex > -1 then
System.Diagnostics.Process.Start(Me.theListBox.SelectedItem.ToString())
end if
end sub
and thats it! alternatively you could combine the filename and location together....
Dim theReader as new System.IO.StreamReader("file.txt")
while theReader.EndOfStream = false
Dim fullFileName as String = theReader.ReadLine()
fullFileName = fullFileName & "\" & theReader.ReadLine()
Me.theListBox.Items.Add(fullFileName)
end while
theReader.Close()
does this help