473,573 Members | 2,835 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView.Ro wCount setting is slow

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.DataGridV iew {

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

protected override void
OnCellValueNeed ed(DataGridView CellValueEventA rgs e)
{
if (!Enabled)
return;
...
}

protected override void OnRowEnter(Data GridViewCellEve ntArgs e)
{
if (!Enabled)
return;
...
}
}

Debug output window contains:

Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.RowCount.s et'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DataGridViewC omboBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.FlatStyle.set '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DisplayStyleF orCurrentCellOn ly.set'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DataGridViewC omboBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.FlatStyle.set '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DisplayStyleF orCurrentCellOn ly.set'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.RowTemplat eClone.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRowCollecti on.Add'
Step into: Stepping over non-user code
'System.Windows .Forms.Control. Enabled.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.OnRowEnter '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.SetCurrent CellAddressCore '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.SetAndSele ctCurrentCellAd dress'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DataGridViewC omboBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.FlatStyle.set '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DisplayStyleF orCurrentCellOn ly.set'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DataGridViewC omboBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.FlatStyle.set '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DisplayStyleF orCurrentCellOn ly.set'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRowCollecti on.this[int].get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.SetSelecte dCellCore'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.SetSelecte dElementCore'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.ClearSelec tion'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.SetAndSele ctCurrentCellAd dress'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.OnRowColle ctionChanged_Po stNotification'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRowCollecti on.InsertCopies Private'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRowCollecti on.Add'

Oct 26 '08 #1
3 5718
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******** **********@TK2M SFTNGP06.phx.gb l...
>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.DataGridV iew {

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

protected override void
OnCellValueNeed ed(DataGridView CellValueEventA rgs e)
{
if (!Enabled)
return;
...
}

protected override void OnRowEnter(Data GridViewCellEve ntArgs e)
{
if (!Enabled)
return;
...
}
}

Debug output window contains:

Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.RowCount.s et'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DataGridViewC omboBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.FlatStyle.set '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DisplayStyleF orCurrentCellOn ly.set'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewColumn.Cell Template.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DataGridViewC omboBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.FlatStyle.set '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DisplayStyleF orCurrentCellOn ly.set'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.CompleteCe llsCollection'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.RowTemplat eClone.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRowCollecti on.Add'
Step into: Stepping over non-user code
'System.Windows .Forms.Control. Enabled.get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.OnRowEnter '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.SetCurrent CellAddressCore '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.SetAndSele ctCurrentCellAd dress'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DataGridViewC omboBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.FlatStyle.set '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DisplayStyleF orCurrentCellOn ly.set'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .DataGridViewTe xtBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.Property Store.GetObject '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewCell.Style. get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewTextBoxCell .Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DataGridViewC omboBoxCell'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.FlatStyle.set '
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.DisplayStyleF orCurrentCellOn ly.set'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewComboBoxCel l.Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.CloneCe lls'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRow.Clone'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRowCollecti on.this[int].get'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.SetSelecte dCellCore'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.SetSelecte dElementCore'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.ClearSelec tion'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.SetAndSele ctCurrentCellAd dress'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid View.OnRowColle ctionChanged_Po stNotification'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRowCollecti on.InsertCopies Private'
Step into: Stepping over non-user code
'System.Windows .Forms.DataGrid ViewRowCollecti on.Add'
Oct 27 '08 #2
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.Collecti ons.Generic;

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

class VirtualModeForm : Form
{
private List<DataObject m_Data = new List<DataObject >();
private List<boolm_Visi ted = new List<bool>();
DataGridView m_Grid = new DataGridView();
public VirtualModeForm ()
{
Controls.Add(m_ Grid);
m_Grid.CellValu eNeeded += OnCellValueNeed ed;
InitData();
InitGrid();
}

private void InitData()
{
for (int i = 0; i < 1000001 + 1; i++)
{
m_Visited.Add(f alse);
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.AutoResi zeColumns(DataG ridViewAutoSize ColumnsMode.Dis playedCellsExce ptHeader);
m_Grid.VirtualM ode = true;
m_Grid.ReadOnly = true;
m_Grid.ColumnCo unt = 108;
// this line causes 8 seconds delay. how to fix.
m_Grid.RowCount = 1000000;
}

private void OnCellValueNeed ed(object sender,
DataGridViewCel lValueEventArgs 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
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(gr id);
grid.VirtualMod e = true;
grid.ColumnCoun t = 108;
// this line causes 8 seconds delay. how to fix.
grid.RowCount = 1000000;
}
}

Andrus.
Oct 28 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1264
by: wackyphill | last post by:
Anyone seen this? Know if its a bug? I'm pretty sure it is. I have a DataGridView control in a tab control who's datasource is a table in a dataset. In certain situations when I add a row to the datasource table I get the following exception which seems to be a bad reference inside the control itself. Any ideas? Here's the exception: ...
3
1325
by: dm1608 | last post by:
Hello, I'm manually populating a DataGridView instead of using Data Binding. How can I clear the contents of all the rows and/or header quickly? My current method is to loop thru the grid backwards and delete each row separately; which is kind of slow. Thanks
0
2965
by: Paul | last post by:
I'm creating a UserControl that uses a DataGridView in virtual mode. It was working fine other than a few bugs. After I fixed those few bugs, I broke it. I have a cache of 50 records. The UserControl loads two pages of the cache (100 records). The DataGridView.RowCount is set to 101. When I scroll down to the third page, the cache...
6
49515
by: Terry Olsen | last post by:
I have two DataGridView's loaded from their respective datasources. I want to highlight rows in one DataGridView that are also in the other DataGridView. But the following code does not work. Looking for some suggestions: Private Sub ShowPlaylistSongsInLibraryGrid() For i As Integer = 0 To gridLibrary.Rows.Count - 1 For j As Integer =...
2
1754
by: ashishtarlekar | last post by:
Hi all, I have to add comboboxes in the first row of datagridview for mapping the database fields. For e.g. I have to show Id, FirstName, LastName in each comboboxes in the first row. if i select a database which contains 2 fields then this data should be displayed from second row so that the user can choose the header name for this two...
1
6966
by: slg | last post by:
I am using virtual mode for datagrid. After i set the rowcount property to 16000, I am receiving datagridview 's CellValueNeeded event 16000 times for each row. This is causing the application to hang for sometime. I am displaying only 16 rows at a time. I am following the sample mentioned in...
2
5939
by: colin | last post by:
Hi, I need to tell how many rows are visible on the screen, in my DataGridView control so that I can ensure my newly selected row is visible without doing any unecessry scrolling, I thought RowCount would give me this :- Summary: Gets or sets the number of rows displayed in the System.Windows.Forms.DataGridView.
1
24900
by: SePp | last post by:
Hello all, I want to display the number of items in an datagridview. I use this one datagridview for different datasets. The datagridview.Rowcount works fine for the most of the dataset. But there is one dataset which has more items than the others and the Rowcount wont work. The result is all the time 0, but it should be something...
2
2031
by: Lloyd Sheen | last post by:
I am trying to find the event (if there is one) which occurs when a row is added to the DataGridView. The closest I can find is the RowsAdded event which says in documentation: Occurs after a new row is added to the System.Windows.Forms.DataGridView. OK then so I debug my code. I am adding 11 rows with a datasource and I get 4...
0
7781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8202
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8066
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6421
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5594
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5292
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3733
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1304
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.