用25k数据填充DataGridView更慢

时间:2018-02-05 19:16:20

标签: vb.net data-binding datagridview datatable

我有一个Windows窗体,它有一个DataGridView(DGVs),可容纳25,000多条记录和15列。通过绑定数据表(如下面的代码

)将数据填充到DGV中
grdSearch.AutoGenerateColumns = False
grdSearch.DataSource = dtStock
grdSearch.Columns(colSearchImage.Index).DefaultCellStyle.NullValue = My.Resources.no_image

它需要太长时间(30秒),还有更多。

所以我的问题是,加载具有大量平均<3 - 5秒的大量数据的DGV的最佳方法是什么?

修改

网格附加了这两个事件,它可能是问题的原因吗?

 Private Sub grdSrch_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdSearch.CellContentClick
        If e.RowIndex = -1 OrElse e.ColumnIndex = -1 Then Exit Sub

        Dim PrID As Integer = grdSearch.Rows(e.RowIndex).Cells(colSearchProdID.Index).Value

        If e.ColumnIndex = colSearchDesc.Index Then
            AddProduct(PrID)
        End If
        grdSearch.SendToBack()
        txtSearch.Text = ""
    End Sub



    Private Sub grdSrch_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles grdSearch.CellPainting
        If e.RowIndex < 0 Then Exit Sub
        Dim dgr As DataGridViewRow = grdSearch.Rows(e.RowIndex)

        If dgr.Cells(colStockBal.Index).Value - dgr.Cells(colCurrSold.Index).Value <= 0 Then
            grdSearch.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.MistyRose

        End If
    End Sub

0 个答案:

没有答案