[resolved] Listview: starting process and populating correct value
This really is not a listview issue, although both stem from using a ListView.
First problem: I am creating a file search tool and I want the files returned to be double clickable. When a ListViewItem is double clicked I want to use Process.Start to open the file.
My ListView looks like this
[File] [Path]
1.jpg c:\images
2.jpg c:\images
And so on.
The problem is, I cannot for the life of me work out how to get the values. Let's say I double click on the first ListViewItem (1.jpg) I would want to open c:\images\1.jpg However I can only seem to access the file column values, never the path column values.
My code to get the file part of the selected row is
My second issue is: When actually populating the ListView the Path column has the file path as well, so for example from the above example it would read c:\images\1.jpg
To extract the filename I did
I cannot fathom how to reverse that, to get everything before the last \
Hope this is clear.
This really is not a listview issue, although both stem from using a ListView.
First problem: I am creating a file search tool and I want the files returned to be double clickable. When a ListViewItem is double clicked I want to use Process.Start to open the file.
My ListView looks like this
[File] [Path]
1.jpg c:\images
2.jpg c:\images
And so on.
The problem is, I cannot for the life of me work out how to get the values. Let's say I double click on the first ListViewItem (1.jpg) I would want to open c:\images\1.jpg However I can only seem to access the file column values, never the path column values.
My code to get the file part of the selected row is
VB.NET:
Dim i As Integer = lstViewSearchResults.SelectedIndices.Item(0).ToString
Dim temp As String = lstViewSearchResults.Items.Item(i).Text
MessageBox.Show(temp)
Process.Start(temp)
My second issue is: When actually populating the ListView the Path column has the file path as well, so for example from the above example it would read c:\images\1.jpg
To extract the filename I did
VB.NET:
Function stripPath(ByVal FullPath As String)
Dim temp As String = ""
Dim i As Integer
i = FullPath.LastIndexOf("\")
temp = FullPath.Substring(i + 1)
Return temp
End Function
Hope this is clear.
Last edited: