Need full path returned from Listview double click event

jumper77

Member
Joined
Jan 23, 2019
Messages
15
Location
Jackson Tennessee
Programming Experience
Beginner
Hi all. I have been trying to loop through processes and put the process icon and name in a Listview. I actually found the solution here before I (just now) became a member. It was a 2008 post where JohnH was helping out. Here's the code. But it has been modified some....
VB.NET:
Private Sub GetProcesses()
        lvProcesses.View = View.Details
        lvProcesses.Columns(0).Width = 600
        For Each p As Process In Process.GetProcesses
            Try
                Dim file As String = p.MainModule.FileName
                lvProcesses.Items.Add(p.ProcessName, file)
                Me.ImageList1.Images.Add(file, Icon.ExtractAssociatedIcon(file))
            Catch ex As Exception
            End Try
        Next
    End Sub

I have one thing left to figure out. On the double click event of the listview, I need it to return the full path to the exe (contaned in the variable "file" in the above sub) It seems like it should be there based on the code, but I can't find a way to do it. And working with Listviews is an area where I'm pretty weak, lol.

So if you don't mind, could someone tell me how to retrieve the full path from the Listview on the double click event?
Thanks in advance for any help. It IS appreciated!
 
Last edited:
Hi John (my name is actually John too). Thank you so much for the help. I knew it had to be there somewhere. The "lvProcesses.FocusedItem.ImageKey" did indeed contain the full path! I will check out the links after I submit this message, so thanks for the those.

I do appreciate the help. Very much!

Is there a way I can give you a +1
 
I noticed that in Details view the icon wouldn't show (ImageList is set for SmallImageList), but if I change the order of code and add to ImageList before adding the ListViewItem then it works.
 
The Detail view works fine for me. Not sure why yours didn't work. I've never used the largeIconList before. I might try that. I think I have to change the size of the icons first though...
 
If you are around sometime John (or anyone), I've noticed that in the Listview, some of the icons are transparent, but some are not. Any idea why that happens?

edit: I realize that some are and some are not transparent, but I know some are, yet they have a square rectangle around them...
 
That's great! I got it to work now. There are 2 things you need to do. One is set the ImageList ColorDepth to 32bit. Then you sent the transparent color to Color.Black (not sure why that works, but it does). Now all my icons are transparent in the Listview.

Thanks a bunch sir!

Here's what I did in the code in case anyone was wondering....
VB.NET:
     lvProcesses.View = View.Details
        lvProcesses.Columns(0).Width = 670
        ImageList1.ColorDepth = ColorDepth.Depth32Bit
        ImageList1.TransparentColor = Color.Black

        lvProcesses.GridLines = False

        For Each p As Process In Process.GetProcesses
            Try
                Dim file As String = p.MainModule.FileName

                lvProcesses.Items.Add(p.ProcessName, file)
                Me.ImageList1.Images.Add(file, Icon.ExtractAssociatedIcon(file))
            Catch ex As Exception
            End Try
        Next
    End Sub

Here's a screen shot so you can see...

Clipboard-1.png
 

Latest posts

Back
Top