Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample app showing DoubleBuffered property on DataGridView
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace DoubleBufferExample
{
public partial class TestForm : Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestForm());
}
Stopwatch _stopwatch = new Stopwatch();
Label _resultLabel;
public TestForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var dummyEntities = BuildEntities();
_resultLabel = label1;
_stopwatch.Restart();
dataGridView1.DataSource = dummyEntities;
}
private void Grids_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
if (e.RowIndex == 15)
{
_stopwatch.Stop();
_resultLabel.Text = _stopwatch.ElapsedMilliseconds.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
var dummyEntities = BuildEntities();
_resultLabel = label2;
_stopwatch.Restart();
dataGridView2.DataSource = dummyEntities;
}
private List<DummyEntity> BuildEntities()
{
var dummyEntities = new List<DummyEntity>();
foreach (var i in Enumerable.Range(1, 16))
{
dummyEntities.Add(new DummyEntity { Id = i, Name = Path.GetRandomFileName() });
}
return dummyEntities;
}
private class DummyEntity
{
public int Id { get; set; }
public string Name { get; set; }
}
}
sealed class DoubleBufferedDataGridView : DataGridView
{
public DoubleBufferedDataGridView()
{
DoubleBuffered = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.