Let me simplify it like this:
On a child MDI form I have a combo box. For the selectionchanged
event of that combo box I want to simply do a this.Close(). This
action ends up bubbling an error to the parent form with the following
exception:
System.Windows.Forms.UnsafeNativeMethods.CallWindo wProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n
at System.Windows.Forms.NativeWindow.DefWndProc(Messa ge& m)\r\n at
System.Windows.Forms.Control.DefWndProc(Message& m)\r\n at
System.Windows.Forms.Control.WmCommand(Message& m)\r\n at
System.Windows.Forms.Control.WndProc(Message& m)\r\n at
System.Windows.Forms.ComboBox.WndProc(Message& m)\r\n at
System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)\r\n
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)\r\n
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)\r\n at System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at
System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)\r\n at
System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)\r\n at
System.Windows.Forms.Application.Run(Form mainForm)\r\n at
FSA.FoodShow.Win32.MDIParent.Main() in mdiparent.cs:line 385
I had a hunch that this might be because I was placing the .close()
command in an event handler that was currently firing, so I took the
approach of actually creating a custom event that the parent MDI
subscribes to and then had the combo box selectionchange event call
that new event. I had the event handler for the new event then try to
close the child window, but that still thows the same error.
So, how am I supposed to have a MDI child close itself?
Any thoughts?
Guy
"Alan Pretre" <no@spam> wrote in message news:<u5**************@TK2MSFTNGP09.phx.gbl>...
"Guy Babbitt" <gu*********@fsafood.com> wrote in message
news:37**************************@posting.google.c om... private void ddlDatabase_SelectedIndexChanged(object sender,
System.EventArgs e)
{
_parent.BuildMenus();
this.Close();
}
The problem is, writing the code this way causes an exception to be
thrown at the following block of code:
Without knowing what BuildMenus() does, have you tried putting a DoEvents()
between BuildMenus() and Close()? If BuildMenus() ends up sending messages
to the MDI children I could see why perhaps things could go awry.
-- Alan