gpt4 book ai didi

c# - StackOverflowException 与 DataGridView

转载 作者:太空狗 更新时间:2023-10-29 20:05:23 26 4
gpt4 key购买 nike

这很奇怪。我有一个 DataGridView。我将其 DataSource 设置为包含我自己的自定义类对象的 List。列表中大约有 50,000 个项目。我定义了我希望在设计器中可见的所有列,并将 AutoGenerateColumns 设置为 false。

只要我将 DataSource 设置到我的列表中,它就会立即正确填充。我可以上下滚动,选择不同的行。一切都是好的。但是,当我一直向下滚动,然后让包含 DataGridView 的窗口失去焦点时,一切都卡住了,过了一会儿,堆栈就这样溢出了:

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
...

出于某种原因,DataGridViewRow.DataGridViewRowAccessibleObject.Bounds.get() 方法将自身调用到遗忘状态。整个堆栈对我来说似乎很奇怪。为什么 Font.Height.get() 会调用 DataGridViewRow

编辑:

我被要求提供一些代码。这是设计器为 DataGridView 及其列生成的代码:

    // 
// 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;

当需要填充 GridView 时,我只需执行以下操作:

dataGridView.DataSource = myList;

最佳答案

修复

目前尚无修复方法。

解决方法

从“控制面板”的“服务”面板禁用Tablet PC 输入服务(又名 tabtip.exe)。

详情

几周前,我就此问题联系了 Microsoft 开发人员支持。我与 WinForms 团队的一名支持工程师进行了通信,我们发现这个问题在某种程度上是由 Accessibility.dll 引起的,每当 Microsoft 的 Tablet PC 输入服务(tabtip。 exe) 正在运行。此服务至少存在于所有 Windows 7 企业版安装中,但通常只有在您拥有平板电脑或曾经在您的电脑上安装过任何类型的笔输入设备时才会运行。我过去曾在我的 PC 上使用过 Wacom Bamboo 数位板,所以运行此服务是有道理的。 请注意,已确定我用来填充 DataGridView 的方法和我设置的任何属性都与该问题无关。

Accessibility.dll 是一个 Microsoft 库,它允许某些外围设备(手写板和特别是辅助设备)更轻松地交互并获取有关表单和表单上包含的控件的额外信息。我对此不是 100% 确定,但我相信如果安装了这样的外围设备,这个库会自动加载到每个正在运行的 Windows 进程中。

在检查了我提供的转储后,Microsoft 工程师对 DataGridView 决定下降的代码路径感到困惑,并发现 Accessibility.dll 是允许让它发生的罪魁祸首。他承认 DataGridView 不应该这样做,这对他们来说似乎是个问题。但是,即使在他的 PC 和新制作的 Windows 7 VM 上都打开了 Tablet PC 输入服务后,他也无法重现该问题。因此,虽然他能够确定导致我的 PC 出现问题的关键因素,但他无法找到根本原因,因此无法进一步追查。

这可能归因于我的特定数位板设备 (Wacom) 或其他原因。它是未知的。如果其他人遇到此问题,请与我联系。如果我能够缩小原因范围,工程师邀请我与他联系。目前,只需关闭该服务即可防止出现此问题。

关于c# - StackOverflowException 与 DataGridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14145811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com