我在做以下嘗試螺紋,但在該行txtBox.Text = DataGridView2.Rows.Item(iloop).Cells(3).Value
得到了「跨線程」的錯誤,任何人都可以點出了什麼問題,謝謝:跨線程操作無效
Dim lm As New Thread(AddressOf load_movie)
Dim lt As New Thread(AddressOf load_timings)
lm.Start()
lt.Start()
Private Sub load_movie()
For iloop As Integer = 0 To DataGridView1.Rows.Count - 2
Dim Cstring As String = "txt_Movie_0" & iloop.ToString
For Each cCtrl As Control In Panel1.Controls
If TypeOf cCtrl Is TextBox Then
Dim txtBox As TextBox
txtBox = cCtrl
If txtBox.Name = Cstring Then
txtBox.Text = DataGridView1.Rows.Item(iloop).Cells(1).Value
End If
End If
Next
Next
End Sub
Private Sub load_timings()
For iloop As Integer = 0 To DataGridView2.Rows.Count - 2
For Each cCtrl As Control In Panel2.Controls
If TypeOf cCtrl Is TextBox Then
Dim txtBox As TextBox
txtBox = cCtrl
If (txtBox.Name.Substring(9, 6)) = (DataGridView2.Rows.Item(iloop).Cells(0).Value.substring(0, 6)) Then
txtBox.Text = DataGridView2.Rows.Item(iloop).Cells(3).Value 'This is the part that says "Cross-thread operation not valid: Control 'txt_Time_00_000' accessed from a thread other than the thread it was created on."
End If
End If
Next
Next
End Sub