在 TextChanged 事件导致对象处置异常后访问组合框项 [C# .NET 4.6]
Accessing a combobox item after TextChanged event results in an object disposed exception [C# .NET 4.6]
问题
我目前正在开发一种表格,其中 datagridview 单元格从 syncfusion 的 multicolumncombobox 工具中获取输入,一切都按预期工作直到我擦除 multicolumncombobox 的文本框然后 select 其他东西
这是我遵循的顺序
- 我擦除 multicolumncombobox 文本框的文本
- 我 select 来自组合框的新值(SelectedValueChanged 事件)
- 抛出异常(尽管在 try/catch 块中但未处理的异常)
异常
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'ComboBoxPopupContainer'.
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.PointToClientInternal(Point p)
at System.Windows.Forms.Control.PointToClient(Point p)
at Syncfusion.Windows.Forms.Tools.ComboDropDown.ComboDropDown_Deactivate(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnDeactivate(EventArgs e)
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.DeactivateMdiChild()
at System.Windows.Forms.Form.WmMdiActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
MDIForm
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/Project/bsp_winforms/bsp_winforms/bin/Debug/MDIForm.exe
----------------------------------------
Syncfusion.Licensing
Assembly Version: 19.4460.0.53
Win32 Version: 19.4460.0.53
CodeBase: file:///D:/Project/bsp_winforms/bsp_winforms/bin/Debug/Syncfusion.Licensing.DLL
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4400.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4360.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4390.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Syncfusion.Shared.Base
Assembly Version: 19.4460.0.53
Win32 Version: 19.4460.0.53
CodeBase: file:///D:/Project/bsp_winforms/bsp_winforms/bin/Debug/Syncfusion.Shared.Base.DLL
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
Syncfusion.Tools.Windows
Assembly Version: 19.4460.0.53
Win32 Version: 19.4460.0.53
CodeBase: file:///D:/Project/bsp_winforms/bsp_winforms/bin/Debug/Syncfusion.Tools.Windows.DLL
----------------------------------------
Syncfusion.Grid.Windows
Assembly Version: 19.4460.0.53
Win32 Version: 19.4460.0.53
CodeBase: file:///D:/Project/bsp_winforms/bsp_winforms/bin/Debug/Syncfusion.Grid.Windows.DLL
----------------------------------------
Accessibility
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Data
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4455.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Numerics
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
UIAutomationProvider
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/UIAutomationProvider/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationProvider.dll
----------------------------------------
WindowsBase
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/WindowsBase/v4.0_4.0.0.0__31bf3856ad364e35/WindowsBase.dll
----------------------------------------
UIAutomationTypes
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/UIAutomationTypes/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationTypes.dll
----------------------------------------
System.Runtime.Serialization.Formatters.Soap
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization.Formatters.Soap/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Runtime.Serialization.Formatters.Soap.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
如果继续单击“继续”,则在应用程序关闭之前会显示此堆栈跟踪
代码
TextChanged 事件
private void aliasMulticolcombobox_TextChanged(object sender, EventArgs e)
{
try
{
aliasMulticolcombobox.SelectedValueChanged += new EventHandler(aliasMulticolcombobox_SelectedValueChanged);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
SelectedValueChanged 事件
private void aliasMulticolcombobox_SelectedValueChanged(object sender, EventArgs e)
{
try
{
ComboBoxBaseDataBound c = aliasMulticolcombobox as ComboBoxBaseDataBound;
if (c.SelectedIndex != -1)
{
DataRowView dv = c.Items[c.SelectedIndex] as DataRowView;
c.Text = dv.Row[0].ToString();
dataGridView1.Rows[currRow].Cells[1].Value = c.Text;
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
到目前为止我尝试了什么
- 检查是否可以使用 aliasMulticolcombobox.PopupContainer.IsAccessible() 函数访问组合框弹出容器
- 检查是否使用 aliasMulticolcombobox.PopupContainer.IsDisposed() 函数处理组合框弹出容器,以便我可以 return 从函数
- 尝试了 .BeforeCloseUp 事件来取消处置调用
- 已尝试切换事件处理程序
尽管做出了所有这些努力,同样的问题仍然存在
我刚刚与 Syncfusion 开发人员联系,他们回复说这是一个错误
We have validated and confirmed the reported scenario is a defect and
logged a report for the reported scenario
“TargetParameterCountException was thrown when selecting the value in
MultiColumnComboBox after clearing the text”. We will provide the
patch for the reported issue on 25th March 2022.
问题
我目前正在开发一种表格,其中 datagridview 单元格从 syncfusion 的 multicolumncombobox 工具中获取输入,一切都按预期工作直到我擦除 multicolumncombobox 的文本框然后 select 其他东西
这是我遵循的顺序
- 我擦除 multicolumncombobox 文本框的文本
- 我 select 来自组合框的新值(SelectedValueChanged 事件)
- 抛出异常(尽管在 try/catch 块中但未处理的异常)
异常
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'ComboBoxPopupContainer'.
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.PointToClientInternal(Point p)
at System.Windows.Forms.Control.PointToClient(Point p)
at Syncfusion.Windows.Forms.Tools.ComboDropDown.ComboDropDown_Deactivate(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnDeactivate(EventArgs e)
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.DeactivateMdiChild()
at System.Windows.Forms.Form.WmMdiActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
MDIForm
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/Project/bsp_winforms/bsp_winforms/bin/Debug/MDIForm.exe
----------------------------------------
Syncfusion.Licensing
Assembly Version: 19.4460.0.53
Win32 Version: 19.4460.0.53
CodeBase: file:///D:/Project/bsp_winforms/bsp_winforms/bin/Debug/Syncfusion.Licensing.DLL
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4400.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4360.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4390.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Syncfusion.Shared.Base
Assembly Version: 19.4460.0.53
Win32 Version: 19.4460.0.53
CodeBase: file:///D:/Project/bsp_winforms/bsp_winforms/bin/Debug/Syncfusion.Shared.Base.DLL
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
Syncfusion.Tools.Windows
Assembly Version: 19.4460.0.53
Win32 Version: 19.4460.0.53
CodeBase: file:///D:/Project/bsp_winforms/bsp_winforms/bin/Debug/Syncfusion.Tools.Windows.DLL
----------------------------------------
Syncfusion.Grid.Windows
Assembly Version: 19.4460.0.53
Win32 Version: 19.4460.0.53
CodeBase: file:///D:/Project/bsp_winforms/bsp_winforms/bin/Debug/Syncfusion.Grid.Windows.DLL
----------------------------------------
Accessibility
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Data
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4455.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Numerics
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
UIAutomationProvider
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/UIAutomationProvider/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationProvider.dll
----------------------------------------
WindowsBase
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/WindowsBase/v4.0_4.0.0.0__31bf3856ad364e35/WindowsBase.dll
----------------------------------------
UIAutomationTypes
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/UIAutomationTypes/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationTypes.dll
----------------------------------------
System.Runtime.Serialization.Formatters.Soap
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization.Formatters.Soap/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Runtime.Serialization.Formatters.Soap.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
如果继续单击“继续”,则在应用程序关闭之前会显示此堆栈跟踪
代码
TextChanged 事件
private void aliasMulticolcombobox_TextChanged(object sender, EventArgs e)
{
try
{
aliasMulticolcombobox.SelectedValueChanged += new EventHandler(aliasMulticolcombobox_SelectedValueChanged);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
SelectedValueChanged 事件
private void aliasMulticolcombobox_SelectedValueChanged(object sender, EventArgs e)
{
try
{
ComboBoxBaseDataBound c = aliasMulticolcombobox as ComboBoxBaseDataBound;
if (c.SelectedIndex != -1)
{
DataRowView dv = c.Items[c.SelectedIndex] as DataRowView;
c.Text = dv.Row[0].ToString();
dataGridView1.Rows[currRow].Cells[1].Value = c.Text;
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
到目前为止我尝试了什么
- 检查是否可以使用 aliasMulticolcombobox.PopupContainer.IsAccessible() 函数访问组合框弹出容器
- 检查是否使用 aliasMulticolcombobox.PopupContainer.IsDisposed() 函数处理组合框弹出容器,以便我可以 return 从函数
- 尝试了 .BeforeCloseUp 事件来取消处置调用
- 已尝试切换事件处理程序
尽管做出了所有这些努力,同样的问题仍然存在
我刚刚与 Syncfusion 开发人员联系,他们回复说这是一个错误
We have validated and confirmed the reported scenario is a defect and logged a report for the reported scenario “TargetParameterCountException was thrown when selecting the value in MultiColumnComboBox after clearing the text”. We will provide the patch for the reported issue on 25th March 2022.