I have a ListView that fills itself with files from a selected Dir in a tree view. Now I need to get the path/filename of the selected item in the listviewinto a variable so I can pass it to another method.
I cant seem to figure it out.
Printable View
I have a ListView that fills itself with files from a selected Dir in a tree view. Now I need to get the path/filename of the selected item in the listviewinto a variable so I can pass it to another method.
I cant seem to figure it out.
see if this little example helps. I just added a listview called lvw with a few items in it (assuming that you know the directory... )Quote:
Originally posted by Jes|er
I have a ListView that fills itself with files from a selected Dir in a tree view. Now I need to get the path/filename of the selected item in the listview.
I cant seem to figure it out.
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim currentDirectory As String = "C:" If Not lvw.SelectedItems Is Nothing Then Dim filePath As String filePath = IO.Path.Combine(currentDirectory, lvw.SelectedItems(0).Text) MsgBox(filePath) End If End Sub
Thank you, been trying to figure this out.
well, did you figure it out or not?:D did that work for you?Quote:
Originally posted by Jes|er
Thank you, been trying to figure this out.
Well, I sort of figured it out. I got it to work.
But the problem now is that the Listview dosnt hold the Path, just the just the file name. So I figure I just have to grab the path from the treeview and conactinate it with the filename. Not sure how I'm going to do that yet. But I'm off to try now. :)
well yeah you could get the path from the treeview too....Quote:
Originally posted by Jes|er
Well, I sort of figured it out. I got it to work.
But the problem now is that the Listview dosnt hold the Path, just the just the file name. So I figure I just have to grab the path from the treeview and conactinate it with the filename. Not sure how I'm going to do that yet. But I'm off to try now. :)
my question is, dont you have the path of the folder at some point? because you are loading all the directories in that folder to the listview, so I guess you have to know the parent folder's path at some point. Why not just save that path in a public variable rather than trying to figure it out again from the treeview?
I wish it was that simple. The treeview lists all the drives on the computer. Its like explorer, only without all the fancy folder gifs :(
So the path is not constant, it changes as the user switchs drives and folders. Sorry I should have made that clear before.
Im currently playing around with Directory.GetCurrentDirectory
and dont seem to be getting anywhere. Well I'll give it another go in the morning.
hmm finding the directory shouldnt be too hard, but displaying them and making them work should be:D I made something like that once in vb6, and it was quite inefficient :p
btw if you just want a directory viewer, there are nice examples of it. Most of them are in C# though...
the "utility library" or whatever its called which is in c# has a nice directory viewer also.