Question How to make DataGridView loads data faster ? (4000+ records)

capedech

Well-known member
Joined
Oct 29, 2008
Messages
62
Programming Experience
Beginner
Hi,
I am making a small POS program using VB.Net and MySQL as the database.
There's more than 4000 items so far and still increasing. It could be 1000 items more.

So, at the Transaction form, I want to call a form which contain all items information a Dialog Form.
It worked perfectly when only less that 100 items in the database.

After I put all the 4000 items data inside the database, when I called the Items Dialog Form, the form didn't show up until 10 seconds.
After I tested my coding, I realise that it all because the DataGridView need sometimes to load all the data.

What should I do to make it load faster ?

Should I show my coding to you ?

Thanks in Advance.

Regards,
 
Hello.

How are you loading the data? Are you using the built-in Database-Connection or an ADO/ODBC-Object?

I've to deal with mostly large data myself, and 3k records took about 3-4 seconds (though, I'm sitting on a Intel Dual @2,00GHz) in my datagrids.

Yes, please show as the parts were you fill the datagridview (if any). Also checkback all your code if there are Events which could possible fire if the datagridview is filled.

Bobby
 
Hello.
How are you loading the data? Are you using the built-in Database-Connection or an ADO/ODBC-Object?
I've to deal with mostly large data myself, and 3k records took about 3-4 seconds (though, I'm sitting on a Intel Dual @2,00GHz) in my datagrids.
Yes, please show as the parts were you fill the datagridview (if any). Also checkback all your code if there are Events which could possible fire if the datagridview is filled.

Bobby
Hi, thanks for replying.
I'm using MySQL Connector .Net, we can download it from MySQL sites.

Here's part of my code :
VB.NET:
Private Sub IsiDgvSearch_Search()
        With DgvSearch
            .Rows.Clear()
            Dim CountLBObjDt As Integer = GetLBObjDt.Rows.Count
            If CountLBObjDt = 0 Then
                .CurrentCell = .Rows(0).Cells(0)
                Exit Sub
            End If

            Dim Search_LBObjDt As String = ""
            For R As Integer = CountLBObjDt - 1 To 0 Step -1
                Search_LBObjDt = GetLBObjDt.Rows(R).Item(BSearch)
                Search_LBObjDt = Search_LBObjDt.ToUpper
                If Search_LBObjDt.Contains(Search) Then
                    If .Rows(0).Cells(1).Value <> Nothing Then .Rows.Insert(0, 1)
                    For C As Integer = 1 To .ColumnCount - 1
                        .Rows(0).Cells(C).Value = GetLBObjDt.Rows(R).Item(C - 1)
                    Next C
                End If
            Next R

            'Pengisian ShortCut
            If .RowCount <> 1 Or .Rows(0).Cells(1).Value <> Nothing Then
                For R As Integer = 0 To .RowCount - 1
                    If R < 10 Then .Rows(R).Cells(0).Value = "F" & (R + 1)
                Next R
            End If

            .CurrentCell = .Rows(0).Cells(0)
        End With
    End Sub

If u need more, tell me which part of the coding that u need and I will provide it. Or I can send u the program if u like.

As u can see, I'm doing the filling data manually. I call the records one by one and fill it one by one to the DataGridView.
Is there any other way to fill the data into DataGridView ?
I've heard binding but I don't know how to code it and don't know whether it can be faster or not.
 
No wonder this is taking long...I've made the same mistake, adding an empty row and looping through all columns to fill them, this is the ultimate slowdown.

What type is GetLBObjDt? Is it a DataTable? If yes, try adding the rows directly...also consider to do the search within the MySQL-Database...that one's a lot faster then you can be.

VB.NET:
DgvSearch.Rows.Add(GetLBObjDt.Rows(0))

Bobby
 
Back
Top