Solved

Populating a datagrid from the filesystem.

Posted on 2006-07-20
3
209 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:scross1276
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Accepted Solution

by:
Justin_W earned 250 total points
ID: 17148067
1. Instantiate a DataTable object.
2. As you find matching files, add a DataRow for each file to the DataTable.
3. When you are done, set the DataTable as the DataGrid's DataSource, and call DataBind().
0
 
LVL 17

Assisted Solution

by:ZeonFlash
ZeonFlash earned 250 total points
ID: 17148204
Just expanding on the method that Justin posted:

Dim dtTable As New DataTable
Dim dr As DataRow

'Add whatever columns you need here
dtTable.Columns.Add("FileName")

For Each File In Searcher.Matches
    dr = dtTable.NewRow
    dr.Item("FileName") = File.FullName
    dtTable.Rows.Add(dr)
Next

dgFiles.DataSource = dtTable
0
 

Author Comment

by:scross1276
ID: 17148286
You two are great, thanks!  I'll split the points.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question