我目前正在VB.net中创建一个文件删除器,虽然由于某些原因我无法将我的文件夹的内容放到列表框中,我的代码如下:
Public Class Form1
Dim dir = "C:\Users\Limited\Desktop\"
Private Sub listbox()
ListBox1.DataSource = _
My.Computer.FileSystem.GetDirectoryInfo( _
dir).GetFiles("*.exe")
ListBox1.DisplayMember = "Name"
ListBox1.ValueMember = "FullName"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
My.Computer.FileSystem.DeleteFile(dir + ListBox1.SelectedItem.ToString)
listbox()
Catch ex As Exception
MsgBox(ErrorToString, MsgBoxStyle.Critical)
End Try
End Sub
End Class
答案 0 :(得分:1)
你忘了.ToList()
ListBox1.DataSource = _
My.Computer.FileSystem.GetDirectoryInfo( _
dir).GetFiles("*.txt").ToList()
ListBox1.DisplayMember = "Name"
ListBox1.ValueMember = "FullName"