Note that there are some explanatory texts on larger screens.

plurals
  1. POStackOverflowException with DataGridView
    primarykey
    data
    text
    <p>This is an odd one. I have a <code>DataGridView</code>. I'm setting its <code>DataSource</code> with a <code>List</code> containing objects of my own custom class. There are about 50,000 items in the list. I defined all of the columns I wanted to be visible in the Designer and set <code>AutoGenerateColumns</code> to false. </p> <p>As soon as I set the <code>DataSource</code> to my list, it is immediately populated correctly. I can scroll up and down, select different rows. Everything is good. But when I scroll all of the way down and then let the window containing the <code>DataGridView</code> lose focus everything freezes up and after a short while the stack overflows as such:</p> <pre><code>System.Drawing.dll!System.Drawing.SafeNativeMethods.Gdip.GdipDeleteGraphics(System.Runtime.InteropServices.HandleRef graphics) + 0x2a bytes System.Drawing.dll!System.Drawing.Graphics.Dispose(bool disposing) + 0x56 bytes System.Drawing.dll!System.Drawing.Graphics.Dispose() + 0x12 bytes System.Drawing.dll!System.Drawing.Font.GetHeight() + 0xc8 bytes System.Drawing.dll!System.Drawing.Font.Height.get() + 0xb bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRow() + 0x44 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.Clone() + 0x44 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRowCollection.this[int].get(int index) + 0xa8 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridView.DataGridViewAccessibleObject.GetChild(int index) + 0xbd bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x76 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() + 0x83 bytes ... </code></pre> <p>For some reason the <code>DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get()</code> method is calling itself into oblivion. The whole stack seems rather strange to me. Why would <code>Font.Height.get()</code> ever call the <code>DataGridViewRow</code>?</p> <p>EDIT:</p> <p>I was asked for some code. This is the designer generated code for the <code>DataGridView</code> and its columns:</p> <pre><code> // // dataGridView // this.dataGridView.AllowUserToAddRows = false; this.dataGridView.AllowUserToDeleteRows = false; this.dataGridView.AllowUserToOrderColumns = true; this.dataGridView.AllowUserToResizeRows = false; this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Window; this.dataGridView.BorderStyle = System.Windows.Forms.BorderStyle.None; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Date, this.Type, this.Job, this.Mix, this.Entry}); this.dataGridView.Location = new System.Drawing.Point(8, 96); this.dataGridView.Name = "dataGridView"; this.dataGridView.ReadOnly = true; this.dataGridView.RowHeadersVisible = false; this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView.Size = new System.Drawing.Size(1152, 504); this.dataGridView.TabIndex = 10; this.dataGridView.SelectionChanged += new System.EventHandler(this.dataGridView_SelectionChanged); // // Date // this.Date.DataPropertyName = "FormattedTime"; this.Date.HeaderText = "Date/Time"; this.Date.Name = "Date"; this.Date.ReadOnly = true; // // Type // this.Type.DataPropertyName = "FormattedType"; this.Type.FillWeight = 60F; this.Type.HeaderText = "Type"; this.Type.Name = "Type"; this.Type.ReadOnly = true; this.Type.Width = 60; // // Job // this.Job.DataPropertyName = "Job"; this.Job.FillWeight = 80F; this.Job.HeaderText = "Job No."; this.Job.Name = "Job"; this.Job.ReadOnly = true; this.Job.Width = 80; // // Mix // this.Mix.DataPropertyName = "Mix"; this.Mix.FillWeight = 80F; this.Mix.HeaderText = "Mix No."; this.Mix.Name = "Mix"; this.Mix.ReadOnly = true; this.Mix.Width = 80; // // Entry // this.Entry.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.Entry.DataPropertyName = "FormattedSummary"; this.Entry.HeaderText = "Entry"; this.Entry.Name = "Entry"; this.Entry.ReadOnly = true; </code></pre> <p>When time comes around to populate the grid view, I simply do a:</p> <pre><code>dataGridView.DataSource = myList; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload