'Open picturefiles with Openfiledialog and list them in CheckedListBox without filepath and show fullpath in Textbox for each item when selected VB

I am using Visual Basic code:

  • Openfiledialog > I want to keep using this.
  • CheckedListBox
  • Textbox
  • Picturebox

My code below is working but I want the CheckedListBox to show only the filename(safefilename) for each image.jpg item from folder and show the fullpath with filename for each CheckedListBox.item selected to show in my textbox, I don't know and can't find the right code for this. (now I am using the fullpath aka openfiledialog1.filenames) somehow I need to combine the openfiledialog.safefilenames with openfiledialog.filenames..

my code sofar:

Private Sub Button1_Click(sender As Object, e As 
EventArgs) Handles Button1_Click
openFiledialog1.Filter = "Pictures(*.jpg*)|*.jpg"

If openFiledialog1.ShowDialog = 
Windows.Forms.DialogResult.OK Then
For Each f As String In openFiledialog1.FileNames
            SuspendLayout()
            CheckedListBox1.Items.Add(f.ToString)
            ResumeLayout()
            TextBox1.Text = f
            For i As Integer = 0 To 
CheckedListBox1.Items.Count - 1
            CheckedListBox1.SetItemChecked(i,True)
            Next
end if


Private Sub 
CheckedListBox1_SelectedIndexChanged(sender As 
Object, e As EventArgs) Handles 
CheckedListBox1.SelectedIndexChanged
    
TextBox1.Text = CheckedListBox1.SelectedItem

    If Not CheckedListBox1.SelectedIndex < 0 Then
        Try
Dim img As Image =  
Image.FromFile(CheckedListBox1.
SelectedItem.ToString())
            
PictureBox1.BackgroundImage = img
        Catch ex As Exception
        End Try
    End If


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source