Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27391

Using Datagridview/backgroundworker and getfileinfo

$
0
0
Hello, kinda new here. Well, new member but learned a lot from here as a guest. I've been trying to figure this out for a while and finally decided to ask for help. Maybe someone can help me figure this out. I'm teaching my self all this so please excuse any horrible formatting. I'm using Visual Studios 2010 Premium. I'm learning on how to use the backgroundworker, but can't seem to get the info passed from the dowork to ProgressChanged. If I use CheckForIllegalCrossThreadCalls = False, it works fine, but I don't want to use that.
  • I have a datagridview with 2 columns added using the designer.
  • I have a backgroundworker using the designer
  • WorkerReportsProgress is set to True

ok, Here is how I start the do_work:

Code:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If Not bgw.IsBusy = True Then
            bgw.RunWorkerAsync()
        End If
End Sub

In the doWork, I have the code to get the File names and lastWriteTime of all the files in the directory.

Code:


Private Sub bgw_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw.DoWork
     
        Dim myDir As ReadOnlyCollection(Of String)
        myDir = FileIO.FileSystem.GetFiles("C:\myDirPath\Directory", FileIO.SearchOption.SearchTopLevelOnly, "*.log")
       
        For Each myFiles In myDir

            Dim files As FileInfo = My.Computer.FileSystem.GetFileInfo(myFile)
            Dim dr As New DataGridViewRow

            dr.CreateCells(DataGridView1)
            dr.Cells(0).Value = files.Name
            dr.Cells(1).Value = files.LastWriteTime

            'Me.DataGridView1.Rows.Add(dr)  <------I only put this here to test using "CheckForIllegalCrossThreadCalls = False" to make sure it does get the file information. 
            bgw.ReportProgress(10, dr)
           
        Next
End Sub

I'd like for the datagridview to load as it gets the file names which I tried like this:

Code:


  Private Sub bgw_ProgressChanged(sender As System.Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles bgw.ProgressChanged
      Me.DataGridView1.Rows.Add(e.userstate)
  End Sub

but when I run the application, I get this:

Attachment 95771

What am I missing?
Attached Images
 

Viewing all articles
Browse latest Browse all 27391

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>