开发者

ListBox GetDirectoryInfo problem

开发者 https://www.devze.com 2023-03-10 02:11 出处:网络
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:

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

精彩评论

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