Saturday, 31 December 2011

VB.NET - LINQ query to get list of files and bind to DataGridView


Cheat sheet to Convert an ArrayList to a DataTable

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                'get files from current directory
        Dim Files = From file In My.Computer.FileSystem.GetFiles(CurDir)
                    Order By file
                    Select file
'returns IEnumerable of FileInfo object that contains file information
        Dim Filesinfo = From File In Files Select My.Computer.FileSystem.GetFileInfo(File)
        'Bind to grid
        'ToList() is to get FileInfo
        DataGridView1.DataSource = Filesinfo.ToList()      
    End Sub

No comments:

Post a Comment