By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

DataGridView.RowCount setting is slow

P: n/a
I have DataGridView in virtual mode containing 3500 rows.
In code below, assigning to RowCount value to 3500 takes 8 seconds.
CPU usage goes high at this time.
Stepping by F11 into user code shows few celltemplate property getters and
combobox/datecombo constructor calls without database access which does not
take a lot of time.

Debug output (below) shows lot of messages Stepping over non-user code.
Running in release mode from Windows this line speed is same (slow).

How to speed up grid creation ?

Using C# Express 2008 3.5 SP1 in Vista.

Andrus.

class Grid : System.Windows.Forms.DataGridView {

internal void SetDataRetriever(DataRetriever<TEntitydataRetrieve r)
{ ......
SuspendLayout();
Enabled = false;
int cnt = DataRetriever.RowCount + (ReadOnly ? 0 : 1);
// next line takes 8 seconds:
RowCount = cnt;
Enabled = true;
ResumeLayout();
}

protected override void
OnCellValueNeeded(DataGridViewCellValueEventArgs e)
{
if (!Enabled)
return;
...
}

protected override void OnRowEnter(DataGridViewCellEventArgs e)
{
if (!Enabled)
return;
...
}
}

Debug output window contains:

Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.RowCount.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dat aGridViewComboBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Fla tStyle.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dis playStyleForCurrentCellOnly.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Clo ne'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dat aGridViewComboBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Fla tStyle.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dis playStyleForCurrentCellOnly.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Clo ne'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.RowTemplateClon e.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRowCollection.Ad d'
Step into: Stepping over non-user code
'System.Windows.Forms.Control.Enabled.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.OnRowEnter'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.SetCurrentCellA ddressCore'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.SetAndSelectCur rentCellAddress'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dat aGridViewComboBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Fla tStyle.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dis playStyleForCurrentCellOnly.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Clo ne'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dat aGridViewComboBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Fla tStyle.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dis playStyleForCurrentCellOnly.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Clo ne'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.Clone'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRowCollection.th is[int].get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.SetSelectedCell Core'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.SetSelectedElem entCore'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.ClearSelection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.SetAndSelectCur rentCellAddress'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.OnRowCollection Changed_PostNotification'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRowCollection.In sertCopiesPrivate'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRowCollection.Ad d'

Oct 26 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
If Rowcount is set to 1, grid opens a much faster.
Any idea why rowcount setting affects to grid creation speed ?

Andrus.

"Andrus" <ko********@hot.eewrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
>I have DataGridView in virtual mode containing 3500 rows.
In code below, assigning to RowCount value to 3500 takes 8 seconds.
CPU usage goes high at this time.
Stepping by F11 into user code shows few celltemplate property getters and
combobox/datecombo constructor calls without database access which does
not take a lot of time.

Debug output (below) shows lot of messages Stepping over non-user code.
Running in release mode from Windows this line speed is same (slow).

How to speed up grid creation ?

Using C# Express 2008 3.5 SP1 in Vista.

Andrus.

class Grid : System.Windows.Forms.DataGridView {

internal void SetDataRetriever(DataRetriever<TEntity>
dataRetriever)
{ ......
SuspendLayout();
Enabled = false;
int cnt = DataRetriever.RowCount + (ReadOnly ? 0 : 1);
// next line takes 8 seconds:
RowCount = cnt;
Enabled = true;
ResumeLayout();
}

protected override void
OnCellValueNeeded(DataGridViewCellValueEventArgs e)
{
if (!Enabled)
return;
...
}

protected override void OnRowEnter(DataGridViewCellEventArgs e)
{
if (!Enabled)
return;
...
}
}

Debug output window contains:

Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.RowCount.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dat aGridViewComboBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Fla tStyle.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dis playStyleForCurrentCellOnly.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Clo ne'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewColumn.CellTempl ate.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dat aGridViewComboBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Fla tStyle.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dis playStyleForCurrentCellOnly.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Clo ne'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.CompleteCellsCo llection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.RowTemplateClon e.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRowCollection.Ad d'
Step into: Stepping over non-user code
'System.Windows.Forms.Control.Enabled.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.OnRowEnter'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.SetCurrentCellA ddressCore'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.SetAndSelectCur rentCellAddress'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dat aGridViewComboBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Fla tStyle.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dis playStyleForCurrentCellOnly.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Clo ne'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Data GridViewTextBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.PropertyStore.GetObject'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewCell.Style.get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewTextBoxCell.Clon e'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dat aGridViewComboBoxCell'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Fla tStyle.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Dis playStyleForCurrentCellOnly.set'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewComboBoxCell.Clo ne'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.CloneCells'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRow.Clone'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRowCollection.th is[int].get'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.SetSelectedCell Core'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.SetSelectedElem entCore'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.ClearSelection'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.SetAndSelectCur rentCellAddress'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridView.OnRowCollection Changed_PostNotification'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRowCollection.In sertCopiesPrivate'
Step into: Stepping over non-user code
'System.Windows.Forms.DataGridViewRowCollection.Ad d'
Oct 27 '08 #2

P: n/a
If Rowcount is set to 1, grid opens a much faster.
Any idea why rowcount setting affects to grid creation speed ?
I created testcase for it.
Line
m_Grid.RowCount = 1000000;

takes 8 seconds.
How to speed it up ?

Andrus.
using System;
using System.Windows.Forms;
using System.Collections.Generic;

class test
{
[STAThreadAttribute()]
public static void Main()
{
Application.Run(new VirtualModeForm());
}
}

class VirtualModeForm : Form
{
private List<DataObjectm_Data = new List<DataObject>();
private List<boolm_Visited = new List<bool>();
DataGridView m_Grid = new DataGridView();
public VirtualModeForm()
{
Controls.Add(m_Grid);
m_Grid.CellValueNeeded += OnCellValueNeeded;
InitData();
InitGrid();
}

private void InitData()
{
for (int i = 0; i < 1000001 + 1; i++)
{
m_Visited.Add(false);
DataObject obj = new DataObject();
obj.Id = i;
obj.Val = 2 * i;
m_Data.Add(obj);
}
}

private void InitGrid()
{
m_Grid.Dock = DockStyle.Fill;
m_Grid.AutoResizeColumns(DataGridViewAutoSizeColum nsMode.DisplayedCellsExceptHeader);
m_Grid.VirtualMode = true;
m_Grid.ReadOnly = true;
m_Grid.ColumnCount = 108;
// this line causes 8 seconds delay. how to fix.
m_Grid.RowCount = 1000000;
}

private void OnCellValueNeeded(object sender,
DataGridViewCellValueEventArgs e)
{

m_Visited[e.RowIndex] = true;
if (e.ColumnIndex == 0)
{
e.Value = m_Data[e.RowIndex].Id;
}
else if (e.ColumnIndex == 1)
{
e.Value = m_Data[e.RowIndex].Val;
}
else if (e.ColumnIndex == 2)
{

Random rand = new Random();
e.Value = rand.Next();
}
}
}

public class DataObject
{
private int m_Id;
private int m_Val;

public int Val
{
get { return m_Val; }
set { m_Val = value; }
}

public int Id
{
get { return m_Id; }
set { m_Id = value; }
}

public int Id1 { get; set; }
public int Id2 { get; set; }
public int Id3 { get; set; }
public int Id4 { get; set; }
public int Id5 { get; set; }
public int Id6 { get; set; }
public int Id7 { get; set; }
public int Id8 { get; set; }
public int Id9 { get; set; }
public int Id10 { get; set; }
public int Id11 { get; set; }
public int Id12 { get; set; }
public int Id13 { get; set; }
public int Id14 { get; set; }
public int Id15 { get; set; }
public int Id16 { get; set; }
public int Id17 { get; set; }
public int Id18 { get; set; }
public int Id19 { get; set; }
public int Id20 { get; set; }
public int Id21 { get; set; }
public int Id22 { get; set; }
public int Id23 { get; set; }
public int Id24 { get; set; }
public int Id25 { get; set; }
public int Id26 { get; set; }
public int Id27 { get; set; }
public int Id28 { get; set; }
public int Id29 { get; set; }
public int Id31 { get; set; }
public int Id32 { get; set; }
public int Id33 { get; set; }
public int Id34 { get; set; }
public int Id35 { get; set; }
public int Id36 { get; set; }
public int Id37 { get; set; }
public int Id38 { get; set; }
public int Id39 { get; set; }
public int Id310 { get; set; }
public int Id311 { get; set; }
public int Id312 { get; set; }
public int Id313 { get; set; }
public int Id314 { get; set; }
public int Id315 { get; set; }
public int Id316 { get; set; }
public int Id317 { get; set; }
public int Id318 { get; set; }
public int Id319 { get; set; }
public int Id320 { get; set; }
public int Id321 { get; set; }
public int Id322 { get; set; }
public int Id323 { get; set; }
public int Id324 { get; set; }
public int Id325 { get; set; }
public int Id326 { get; set; }
public int Id327 { get; set; }
public int Id328 { get; set; }
public int Id329 { get; set; }
public int Id401 { get; set; }
public int Id402 { get; set; }
public int Id403 { get; set; }
public int Id404 { get; set; }
public int Id405 { get; set; }
public int Id406 { get; set; }
public int Id407 { get; set; }
public int Id408 { get; set; }
public int Id409 { get; set; }
public int Id4010 { get; set; }
public int Id4011 { get; set; }
public int Id4012 { get; set; }
public int Id4013 { get; set; }
public int Id4014 { get; set; }
public int Id4015 { get; set; }
public int Id4016 { get; set; }
public int Id4017 { get; set; }
public int Id4018 { get; set; }
public int Id4019 { get; set; }
public int Id4020 { get; set; }
public int Id4021 { get; set; }
public int Id4022 { get; set; }
public int Id4023 { get; set; }
public int Id4024 { get; set; }
public int Id4025 { get; set; }
public int Id4026 { get; set; }
public int Id4027 { get; set; }
public int Id4028 { get; set; }
public int Id4029 { get; set; }
public int Id4031 { get; set; }
public int Id4032 { get; set; }
public int Id4033 { get; set; }
public int Id4034 { get; set; }
public int Id4035 { get; set; }
public int Id4036 { get; set; }
public int Id4037 { get; set; }
public int Id4038 { get; set; }
public int Id4039 { get; set; }
public int Id40310 { get; set; }
public int Id40311 { get; set; }
public int Id40312 { get; set; }
public int Id40313 { get; set; }
public int Id40314 { get; set; }
public int Id40315 { get; set; }
public int Id40316 { get; set; }
public int Id40317 { get; set; }
public int Id40318 { get; set; }
public int Id40319 { get; set; }
public int Id40320 { get; set; }
public int Id40321 { get; set; }
public int Id40322 { get; set; }
public int Id40323 { get; set; }
public int Id40324 { get; set; }
public int Id40325 { get; set; }
public int Id40326 { get; set; }
public int Id40327 { get; set; }
public int Id40328 { get; set; }
public int Id40329 { get; set; }
}

Oct 27 '08 #3

P: n/a
Here is simpler testcase to reproduce 8 sec delay:

using System;
using System.Windows.Forms;

class Test
{
public static void Main()
{
Application.Run(new VirtualModeForm());
}
}

class VirtualModeForm : Form
{
DataGridView grid = new DataGridView();
public VirtualModeForm()
{
Controls.Add(grid);
grid.VirtualMode = true;
grid.ColumnCount = 108;
// this line causes 8 seconds delay. how to fix.
grid.RowCount = 1000000;
}
}

Andrus.
Oct 28 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.