从后台线程向DataGridView添加行

时间:2017-10-21 10:51:05

标签: vb.net multithreading datagridview

编辑:更改了问题。

有没有办法在没有冻结UI的情况下将行添加到Datagridview?

我试过了:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim t As New Threading.Thread(AddressOf CreateRows)
    t.IsBackground = True
    t.Start()
End Sub

Private Sub CreateRows()
    If DataGridView1.InvokeRequired Then
        DataGridView1.Invoke(New MethodInvoker(AddressOf CreateRows))
    Else
        For x = 0 To 25000
            DataGridView1.Rows.Add(x)
        Next
    End If
End Sub

0 个答案:

没有答案