Skip to content

Exception occurred when add DataGridView editing controls to other control in .Net Core #2138

@Lily721

Description

@Lily721

.Net Core version: 3.0.1
OS version: win10 64-bit

Please try my sample, when add MS control to Panel, there's always an exception occurred:

///
/// exception occurred when they are added to Panel, I believe there're more MS controls have same issue.
///

///this.panel1.Controls.Add(new ToolStripDropDown());
//this.panel1.Controls.Add(new ToolStripDropDownMenu());
//this.panel1.Controls.Add(new ContextMenuStrip());
//this.panel1.Controls.Add(new ToolStripDropDown());
//this.panel1.Controls.Add(new DataGridViewTextBoxEditingControl());
this.panel1.Controls.Add(new DataGridViewComboBoxEditingControl());
System.NullReferenceException: Object reference not set to an instance of an object.
  at System.Windows.Forms.DataGridViewComboBoxEditingControl.OnHandleCreated(EventArgs e) in /_/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxEditingControl.cs:line 164
   at System.Windows.Forms.Control.WmCreate(Message& m) in /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs:line 12452
   at System.Windows.Forms.Control.WndProc(Message& m) in /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs:line 13486
   at System.Windows.Forms.ComboBox.WndProc(Message& m) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs:line 4051
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) in /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.ControlNativeWindow.cs:line 65
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) in /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.ControlNativeWindow.cs:line 113
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) in /_/src/System.Windows.Forms/src/System/Windows/Forms/NativeWindow.cs:line 626

I checked the source code, this bug dues to some internal control override OnHandleCreated method, but didn't check if parent control exists or not, see below:

        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);
            dataGridView.SetAccessibleObjectParent(this.AccessibilityObject);
        }

InternalControlTest.Core.zip

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions