To get file name only, use:
Path.GetFileName Method (System.IO) | Microsoft Docs[
^]
To get directory name only, use:
Path.GetDirectoryName Method (System.IO) | Microsoft Docs[
^]
I suggest to create
List[
^](of
FileInfo[
^]) which will hold all your files. Then bind it with
CheckedListBox1
via
CheckedListBox.DataSource Property (System.Windows.Forms) | Microsoft Docs[
^]
Note: FileInfo
class has several properties/fields you can use, for example:
FileInfo.DirectoryName Property (System.IO) | Microsoft Docs[
^]
FileInfo.Name Property (System.IO) | Microsoft Docs[
^]
[EDIT]
benngia wrote:
Thank you for your feedback, My knowledge is still too basic for implementing this, I'm trying for days now, I'm stuck. :(
Well... seems you want to get a fish, instead of a fishing rod.
So, i've prepared
LinqPad 5[
^] script. As you can see, there's few differences (for example: DataGridView instead of CheckedListBox), but the idea is the same.
I hope it would be helpful to you.
Sub Main
Dim mf As New MyForm
mf.Show()
End Sub
Public Class MyForm
Inherits Form
Private DataGridView1 As New DataGridView()
Private PictureBox1 AS New PictureBox()
Private TextBox1 AS New TextBox()
Private Pictures As List(Of FileInfo)
Private InitialPath As String
Private Sub InitializeMyControls()
Me.Size = New Size(850, 720)
Me.WindowState = FormWindowState.Maximized
With DataGridView1
.Size = New Size(300,650)
.Location = New Point(10,10)
.Anchor = (AnchorStyles.Top OR AnchorStyles.Left OR AnchorStyles.Bottom)
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.RowHeadersVisible = False
AddHandler .SelectionChanged, AddressOf DataGridView1_SelectionChanged
End With
With TextBox1
.Size = New Size(500,24)
.Location = New Point(330,10)
.Anchor = (AnchorStyles.Top OR AnchorStyles.Left OR AnchorStyles.Right)
End With
With PictureBox1
.Size = New Size(500,610)
.Location = New Point(330,40)
.Anchor = (AnchorStyles.Top OR AnchorStyles.Left OR AnchorStyles.Right OR AnchorStyles.Bottom)
End With
Me.Controls.Add(DataGridView1)
Me.Controls.Add(TextBox1)
Me.Controls.Add(PictureBox1)
End Sub
Public Sub New()
InitializeMyControls()
InitialPath = "C:\Users\YourWindowsLoginHere\Pictures\"
Pictures = Directory.GetFiles(InitialPath,"*.jpg").Select(Function(x) New FileInfo(x)).ToList()
With DataGridView1
.DataSource = Pictures
For i As Integer = .Columns.Count() - 1 To 1 Step -1
.Columns(i).Visible = False
Next
End With
End Sub
Private Sub DataGridView1_SelectionChanged(sender As Object, e As EventArgs)
Dim dgr As DataGridViewRow = DataGridView1.CurrentRow
If dgr Is Nothing Then Exit Sub
Try
Dim img As Image = Image.FromFile(dgr.Cells("FullName").Value)
TextBox1.Text = dgr.Cells("DirectoryName").Value
PictureBox1.Image = img
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class