Results 1 to 8 of 8

Thread: Current Selected Item (file) in Listview To String...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83

    Current Selected Item (file) in Listview To String...

    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.
    Last edited by Jes|er; Jan 20th, 2003 at 12:37 AM.
    12/32/84 - I need some code to make me a sandwhich.

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Current Selected Item (file) in Listview To String...

    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.
    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... )
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim currentDirectory As String = "C:"
    3.         If Not lvw.SelectedItems Is Nothing Then
    4.             Dim filePath As String
    5.             filePath = IO.Path.Combine(currentDirectory, lvw.SelectedItems(0).Text)
    6.  
    7.             MsgBox(filePath)
    8.         End If
    9.     End Sub
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    Thank you, been trying to figure this out.
    12/32/84 - I need some code to make me a sandwhich.

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by Jes|er
    Thank you, been trying to figure this out.
    well, did you figure it out or not? did that work for you?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    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.
    Last edited by Jes|er; Jan 20th, 2003 at 08:58 PM.
    12/32/84 - I need some code to make me a sandwhich.

  6. #6
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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.
    well yeah you could get the path from the treeview too....
    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?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    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.
    12/32/84 - I need some code to make me a sandwhich.

  8. #8
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hmm finding the directory shouldnt be too hard, but displaying them and making them work should be I made something like that once in vb6, and it was quite inefficient
    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.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

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