ListBox GetDirectoryInfo problem
I am current creating a file deleter in VB.net, although for some reason I am unable to get the contents of my folder on to the listbox, my code is as follows:
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_开发者_JAVA百科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
You forgot .ToList()
ListBox1.DataSource = _
My.Computer.FileSystem.GetDirectoryInfo( _
dir).GetFiles("*.txt").ToList()
ListBox1.DisplayMember = "Name"
ListBox1.ValueMember = "FullName"
精彩评论