Why slow dataGridView?

There is a WinForms project, it is a dataGridView in the form designer, the following code:

dataGridView1.RowCount = 36;
dataGridView1.ColumnCount = 30;
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dataGridView1.Font = new Font(dataGridView1.Font, FontStyle.Bold);

The property grid Dock = Fill.
Like rows and columns of anything, but with a smooth change of the size of the form begin terrible brakes.
Also in the KeyDown event handler is some code that when you press the space bar paint in a different color of a grid cell depending on its content:
if (e.KeyCode == Keys.Space)
 char ch = Convert.ToChar(dataGridView1.Rows[currentRow].Cells[currentCol].Value);
 if(ch == defaultChar)
 dataGridView1.Rows[currentRow].Cells[currentCol].Style.BackColor = Color.Yellow;
 else dataGridView1.Rows[currentRow].Cells[currentCol].Style.BackColor = Color.Coral;

And then also, when painting the cell there is a short, but noticeable and critical for my tasks hang for about 0.5 seconds(you want to immediately use the keypad to move to the next cell). If you make the table size 10x15, then the lag is almost there, it is barely noticeable, but still. The application runs on a machine with i7-4790 3.6 GHz.

Why dataGridView is so slow and is there a way to fix it?
July 9th 19 at 13:20
4 answers
July 9th 19 at 13:24
DataGridView in principle slows down when a large amount of data (Google to confirm). You can make padding or custom...grid.
July 9th 19 at 13:22
DoubleBuffered = true
Attempt not torture.
July 9th 19 at 13:26
What is the line of code slows down? Measure.

var watch = System.Diagnostics.Stopwatch.StartNew();
// your code

Check the property grid's AutoSizeColumnsMode - put it in None. Gives the effect? You can still check out each column property AutoSizeMode.

Well, get a variable or something - since access to it in any case 2 times.

var cell = dataGridView1.Rows[currentRow].Cells[currentCol];
July 9th 19 at 13:28
You can go for WPF, DataGrid there is drawn by DirectX so rendering is faster, the application startup will slow down the RAM consumption will increase ease of development will be reduced, the DataGrid itself is very different from the DataGridView.

Find more questions by tags C#ProgrammingWindows Forms