Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DataGridView RowCount set is slow

DataGridView RowCount set is slow

Scheduled Pinned Locked Moved C#
csharpcssdatabasedebuggingperformance
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrusM
    wrote on last edited by
    #1

    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.

    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.CellTemplate.get' Step into: Stepping over non-user code 'System.Windows.Forms.DataGridView.CompleteCellsCollection' Step into: Stepping over non-user code 'System.Windows.Forms.DataGridViewColumn.CellTemplate.get' Step into: Stepping over non-user code 'System.Windows.Forms.DataGridView.CompleteCellsCollection' Step into: Stepping over non-user code 'System.Windows.Forms.DataGridViewTextBoxCell.DataGridViewTextBoxCell' 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.Clone' Step into: Stepping over non-user code 'System.Windows.Forms.DataGridView.CompleteCellsCollection' Step into: Stepping over non-user code 'System.Windows.Forms.DataGridViewColumn.CellTemplate.get' Step into: Stepping over non-user code 'System.Windows.Forms.DataGridView.CompleteCellsCollection'

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups