Link to home
Start Free TrialLog in
Avatar of Steve
SteveFlag for United States of America

asked on

Populating a datagrid from the filesystem.

I need to populate a datagrid with the files returned from any path the user provides.  I can get this to work using a listbox, which that code is also provided below, but I can't get it to populate the datagrid.  Can anyone help me with this??

The datagrid portion is at the bottom of the code block.


    Public Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
        Dim Searcher As New FileSearcher("*.*")
        Dim strFilePath As String

        strFilePath = txtPath.Text



        '***********Listbox Code*************
        ' Perform a single-directory search.
        Searcher.Search(strFilePath, False)

        ' Display results.
        Dim File As FileInfo
        For Each File In Searcher.Matches
            lbFiles.Items.Add(File.FullName)
        Next

        ' Perform a recursive directory search.
        Searcher.Search(strFilePath, True)

        ' Display results.
        For Each File In Searcher.Matches
            lbFiles.Items.Add(File.FullName)
        Next
        '*******End of Listbox Code***********



        '***********Datagrid Code*************
        dgFiles.DataSource = File.FullName
        dgFiles.DataBindings.Add(File.FullName)
        '*******End of Datagrid Code**********

        lblCount.Text = lbFiles.Items.Count

End Sub
ASKER CERTIFIED SOLUTION
Avatar of Justin_W
Justin_W

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steve

ASKER

You two are great, thanks!  I'll split the points.