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'
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'
Comment