Click here to Skip to main content
14,921,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

Data Grid View getting very slow when I am loading large amount of data.

and also I want to show one column based on condition
That Data grid view column is Check Box Column.

so I am having check box (out side the Data grid view control)

1. If I checked that out side check box then one addition column shown in Data grid view.
All rows are unchecked by default. user checked that data grid view rows manually.


2. unchecked that out side check box column then hide Data grid view that particular column.
All rows are Checked by default.

So that I reload whole Data grid view again and again.

i. Data Grid View having minimum 10,000 rows,
ii. if I press start button then execute line by line using thread,
(checked rows execute, unchecked rows not execute)
iii. All records are getting from XML file and bind to data grid view directly.
Not using SQL server or any data bases other than XML file.

Please provide solution. How to do data grid view loading very fast.
Updated 10-Jun-14 0:34am

May be, dataGridView in VirtualMode will be a solution?
adriancs 10-Jun-14 21:57pm
Yes, this will solve.
See the below link it is very useful to you

SQL Server 2005 Paging Results[^][^]

Thread is executing line by line from data grid view rows,
so user want to see all rows [Not required paging this scenario].
I don't think so. Who on this earth would like to see so many records on one Page?

If User/Client is refusing, then convince him/her telling that how we can achieve better performance in terms of Paging. That is the best way to handle these much of data.
Tino Fourie 12-Jul-14 15:22pm
I assume that you are assuming that a user is actually sitting at their desk scrolling through 10k lines in a DataGrid. However, it is more likely that the data in the datagrid could be used by other processes in the application and will require all the data to be present. To incorporate Paging to be triggered automatically by another process and not by user interaction through scrolling seems like a daunting exercise.

It is also possible that the OP is not quite clear on how the data is used by the user which validates your reply.
WinForm is unlike ASP.NET (Web Application). ASP.NET is sending data through internet connection. There is a performance issue if you are sending large data to client's web browser.

But in WinForm development, the data is transmitting within the memory of computer. Hundred thousands of rows is sent and received almost instantly. You can load Hundred Thousands of rows at once at DataGridView. No problem.

You just need to implement VirtualMode of DataGridView control.
By enabling VirtualMode = true, DataGridView is not holding any actual data.
The data is retrieved from other source such as DataTable, List<object>, etc.
Therefore, the DataGridView will consume very little of memory.

Here is some of the basic intro about VirtualMode. For more details, you may Google it.

(Note: Code Tested)
public partial class Form1 : Form
    Random rd = new Random();
    DataTable dt = new DataTable();

    public Form1()


        DataGridView dataGridView1 = new DataGridView();
        dataGridView1.Dock = DockStyle.Fill;
        dataGridView1.VirtualMode = true;
        dataGridView1.CellValueNeeded += dataGridView1_CellValueNeeded;

        dataGridView1.DataSource = dt;

    void dataGridView1_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
        if (e.RowIndex >= dt.Rows.Count)

        if (e.ColumnIndex >= dt.Columns.Count)

        e.Value = dt.Rows[e.RowIndex][e.ColumnIndex];

    void CreateSampleData()

        Random rd = new Random();

        for (int i = 0; i < 1000000; i++)

    private string[] GetRandomData()
        string[] sa = new string[5];
        for (int i = 0; i < sa.Length; i++)
            sa[i] = rd.Next(0, int.MaxValue).ToString();
        return sa;
If you are using winforms:
- Verify you disabled autosizing (Grid.AutoSizeColumnsMode, Grid.AutoSizeRowsMode, Column.AutoSizeMode).
- set grids DoubleBuffered property to true. The property is protected, you have to inherit your own grid.
The simple answer is: Do not load all the 10000 rows at one go. Implement a paging mechanism where only the currenly displayed rows are fetched from the database and displayed. You can find an example here[^].
Mohankumar.Engain 10-Jun-14 6:02am
Hi Shameel,
Thread is executing line by line from data grid view rows,
so user want to see all rows [Not required paging this scenario].
[no name] 10-Jun-14 6:16am
If you have already written the code, edit your question and include your code. If the data is loaded asynchronously using Ajax calls as the grid is scrolled, then you need to concentrate your efforts on 1. improving database performance using Indexes, 2. read rows as a batch (say 10 rows instead of single rows), 3. Improve network speed by using JSON instead of XML, etc.
SherifMohamedReda 2-Aug-16 5:54am
Solution 3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900