The thread question is self explanatory. Just Wanted to Know that below 2 Options with coding to load Image from ListBox Selected Item.
Private Sub ListBoxFileNames_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBoxFileNames.SelectedIndexChanged
'Option 1
Dim path As String = "C:"
Dim di As New System.IO.DirectoryInfo("C:NAMEImagesDirections")
Dim dirAndParent As String = $"{(path)}{di.Parent}{""} {di.Name}{""}"
Dim listBoxPathOfImages As String = dirAndParent & ListBoxFileNames.SelectedItem.ToString
If ListBoxFileNames.SelectedIndex <> -1 Then
MsgBox(listBoxPathOfImages)
PictureBox1.Image = Image.FromFile(listBoxPathOfImages)
End If
Why does Above Option throw the Error system.io.filenotfoundexception to load Image?
The below Method works Perfectly
'Option 2
Dim dirAndParent2 As String = "C:NAMEImagesDirections"
Dim listBoxPathOfImages2 As String = dirAndParent2 & ListBoxFileNames.SelectedItem.ToString
If ListBoxFileNames.SelectedIndex <> -1 Then
MsgBox(listBoxPathOfImages)
PictureBox1.Image = Image.FromFile(listBoxPathOfImages)
End If
Can someone explain Why the Error Generated and How to achieve the result with Option 1
Tried Option 1 of this thread but got error
Thanks SsD