Let me simplify it like this:
On a child MDI form I have a combo box. For the selectionchange d
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.UnsafeNat iveMethods.Call WindowProc(IntP tr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n
at System.Windows. Forms.NativeWin dow.DefWndProc( Message& m)\r\n at
System.Windows. Forms.Control.D efWndProc(Messa ge& m)\r\n at
System.Windows. Forms.Control.W mCommand(Messag e& m)\r\n at
System.Windows. Forms.Control.W ndProc(Message& m)\r\n at
System.Windows. Forms.ComboBox. WndProc(Message & m)\r\n at
System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)\r\n
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)\r\n
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)\r\n at System.Windows. Forms.Component Manager.System. Windows.Forms.U nsafeNativeMeth ods+IMsoCompone ntManager.FPush MessageLoop(Int 32
dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at
System.Windows. Forms.ThreadCon text.RunMessage LoopInner(Int32 reason,
ApplicationCont ext context)\r\n at
System.Windows. Forms.ThreadCon text.RunMessage Loop(Int32 reason,
ApplicationCont ext context)\r\n at
System.Windows. Forms.Applicati on.Run(Form mainForm)\r\n at
FSA.FoodShow.Wi n32.MDIParent.M ain() in mdiparent.cs:li ne 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******* *******@TK2MSFT NGP09.phx.gbl>. ..
"Guy Babbitt" <gu*********@fs afood.com> wrote in message
news:37******** *************** ***@posting.goo gle.com... private void ddlDatabase_Sel ectedIndexChang ed(object sender,
System.EventArg s e)
{
_parent.BuildMe nus();
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