473,411 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Close an MDI child window

I have an MDI application that starts an instance of a child form at
application start. I have an event handler on a combo box checking
for the selected value to change. When the select value changes, I
call a method on the parent form to change some menu options, and then
I need to close the child form. My code looks something like this:

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:

static void Main()
{
Application.Run(new MDIParent());
}

on the parent form. I have tried a variety of things, but am not sure
of the right way to go about this.

Can someone shed some light for me?

Guy
Nov 15 '05 #1
2 8993
"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
Nov 15 '05 #2
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

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joe D | last post by:
I think this is a simple question. But I am new to JS. Here is what I want to do: From a parent window, open a popup window (child) to get data from user, then user submit the request, close the...
2
by: Irvin Amoraal | last post by:
Process: I have a form which uploads a file from client to server written in PHP. When the user presses the submit button, I use the "onSubmit" event to execute javascript to open a child window...
6
by: | last post by:
In IE, from the child window of a frameset i use the function top.window.close() And this works in IE, but not in nn4! How can i make this same effect in nn4? please help
28
by: PerryC | last post by:
Anyone know how to auto close the parent / opener window without confirmation? I have tried: <script> opener.window.close() </script> ----I put it in the child html page, and nothing...
1
by: gopal srinivasan | last post by:
I need to know how to close a parent modal window when child modal window opens, also i need to know the syntax for writing document on the modal window on the fly, like what we do in case of...
3
by: Isabel | last post by:
How can you close all child browser windows that where open by a parent browser window? I have links on a parent (main) page that opens the child page as a separate browser. However, I need to be...
2
by: Paul | last post by:
Hi this is related to a previous post, hopefully just a bit clearer description o the problem. I have a parent form that opens a new form (child form) while still leaving the parent form open....
3
by: Volodymyr Lozovoy | last post by:
Help novice I open new window using window.open(), then user click button in this window and i create file and return it user using Response.Redirect(fileName). How i can close the window after...
7
by: Jaggu | last post by:
Hi , I need to close main window, once the child window succesfully opens else main window to remain. In my case when I close the main window immediately after the "window.open()" as mentioned...
1
by: michal.podlewski | last post by:
Hi All, I have a problem with a simple (as I thought till now) thing: I want to make a link in a child-window which would change site in the parent-window and along with closing child window. The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.