Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Populating a datagrid from the filesystem.

Posted on 2006-07-20
3
Medium Priority
?
210 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 1000 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 1000 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

Independent Software Vendors: 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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