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




Reply With Quote
