开发者

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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜