Results 1 to 9 of 9

Thread: Get count of datagridview inside a thread

Threaded View

  1. #1

    Thread Starter
    Lively Member Christhemist's Avatar
    Join Date
    Sep 2016
    Location
    Nevada
    Posts
    116

    Get count of datagridview inside a thread

    Update: It does not appear that I can access anything from the DataGridView from within my thread.... I am trying to just simply pull some information from a cell and I am getting this error: "Index was out of range. Must be non-negative and less than the size of the collection." Why is it not working with my DataGridView????

    I am trying to loop through my DataGridView using a thread, but it does not appear to be getting the proper count; therefor it is unable to loop through my DataGridView.

    Notes: My DataGridView is on a separate form and is being populated before the thread is executed. The thread is executed by a button on a separate form from the DataGridView.

    Here is the code from the form trying to run the thread: (The code in bold returns a value of -1)

    Code:
    Public thread_UpdateDGVCheckBox As Threading.Thread
    
    
    Private Sub ThreadedDGVCheckBoxUpdate()
    
            Dim TST As String
            Dim StringCnt As Integer
    
            StringCnt = DGV_Form.DataGridView1.RowCount - 1
            MsgBox(StringCnt)
    
            For counter As Int32 = 0 To DGV_Form.DataGridView1.RowCount - 1
                TST = DGV_Form.DataGridView1.Item(3, DGV_Form.DataGridView1.Rows(counter).Index).Value.ToString()
                If TST = "loc_132" Then
                    DGV_Form.Invoke(Sub()
                                            DGV_Form.DataGridView1.CurrentRow.DefaultCellStyle.ForeColor = Color.Red
                                            DGV_Form.DataGridView1(0, DGV_Form.DataGridView1.Rows(counter).Index).Value = True
                                        End Sub)
                End If
            Next
        End Sub
    
    
    
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button11.Click
    
            thread_UpdateDGVCheckBox = New Threading.Thread(AddressOf ThreadedDGVCheckBoxUpdate)
            thread_UpdateDGVCheckBox.Start()
    
    End Sub
    Last edited by Christhemist; Nov 15th, 2016 at 05:19 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width