473,418 Members | 2,056 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,418 software developers and data experts.

MDI Child Form Close Problem

Hey guys, maybe someone can help me with some MDI issues I have. A
co-worker asked me a very simple question, one that I blew off as trivial,
and it has become a time-consuming issue.

Simply put, there is an MDIForm and a child form.

The MDIForm does the usual from within its constructor...

this.IsMdiContainer = true;
Form2 frm = new Form2();
frm.MdiParent = this;
frm.Show();

Okay, so nothing special there.

The child form then has a combobox on it. The question was, how do I get my
child form to close if I pick a particular item from the combobox. Or, to
make it easier, close the child form when the item selection changes in the
combobox.

So the following is in the child form...

private void comboBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
this.Close();
}
Unfortunately this throws an exception indicating that the combobox has
already disposed itself and a null-reference exception is raised.

So I suggested the following...

private void comboBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
this.Dispose(false);
}

This gets rid of the exception, but the child form is really not disposed,
even though visually it looks like it has gone away. It can be made to come
back sporadically by clicking inside the MDI parent form.

Using a true argument in the Dispose yields the same null pointer exception.

So with that, my understanding of forms went down the tubes, along with my
understanding of how the GC works and how correct implementations of
IDisposable work.

Can someone comment on how to get an MDI child form to close itself (i.e.
commit suicide)? Closing the child from a menu or toolbar on the parent
form is not a problem.

Thanks in advance.

MD

Nov 15 '05 #1
1 4206
Maybe try unsetting the MDIParent property before calling Close

just a thought
--
Eric Newton
APTItude Solutions
en*****@aptic.com.nospam

"Martin Douglas" <ma************@lycos.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
Hey guys, maybe someone can help me with some MDI issues I have. A
co-worker asked me a very simple question, one that I blew off as trivial,
and it has become a time-consuming issue.

Simply put, there is an MDIForm and a child form.

The MDIForm does the usual from within its constructor...

this.IsMdiContainer = true;
Form2 frm = new Form2();
frm.MdiParent = this;
frm.Show();

Okay, so nothing special there.

The child form then has a combobox on it. The question was, how do I get my child form to close if I pick a particular item from the combobox. Or, to
make it easier, close the child form when the item selection changes in the combobox.

So the following is in the child form...

private void comboBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
this.Close();
}
Unfortunately this throws an exception indicating that the combobox has
already disposed itself and a null-reference exception is raised.

So I suggested the following...

private void comboBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
this.Dispose(false);
}

This gets rid of the exception, but the child form is really not disposed,
even though visually it looks like it has gone away. It can be made to come back sporadically by clicking inside the MDI parent form.

Using a true argument in the Dispose yields the same null pointer exception.
So with that, my understanding of forms went down the tubes, along with my
understanding of how the GC works and how correct implementations of
IDisposable work.

Can someone comment on how to get an MDI child form to close itself (i.e.
commit suicide)? Closing the child from a menu or toolbar on the parent
form is not a problem.

Thanks in advance.

MD

Nov 15 '05 #2

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

Similar topics

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...
2
by: Brindley | last post by:
Hi there, In my Mdi application, I have placed a set of controls on the parent form to call child forms. The problem is that the controls hide the child forms. I have used SendToBack when Im...
2
by: zobie | last post by:
In the parent of my MDI application I declare a child form private frmChild = null; which is to be activated on a menu click. In the click event I am using the following code: if (frmChild...
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....
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
7
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
14
by: Simon Abolnar | last post by:
I would like to know how to open child form from dialog form. Thanks for help! Simon
13
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
3
by: Adam Right | last post by:
Hi, I am developing an application which has established on MDI Form and there are many MDI Child forms. My problem is starting when i close the mdi child forms. They are not disposed from the...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.