Created
September 2, 2012 08:12
-
-
Save orangutanboy/3595772 to your computer and use it in GitHub Desktop.
Sample app showing DoubleBuffered property on DataGridView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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