Click here to Skip to main content
11,923,046 members (62,022 online)
Rate this:
Please Sign up or sign in to vote.
See more: .NET3.0 C# .NET
i m using windows aaplication and i have 2 windows form ,first is mdi parent and another is mdi child.parent form contain the link of child form .whenever i run my parent form and click link button then child page open ,and then i click cancel button then form get closed.i try to again open child page but when i click lick button then i m getting a error message like "Cannot access a disposed object.
Object name: 'obj'".
Posted 17-Nov-12 16:40pm
shambhoo kumar 17-Nov-12 22:21pm
Any one help me.....
Sergey Alexandrovich Kryukov 17-Nov-12 22:24pm
Any particular reason to use MDI?
shambhoo kumar 17-Nov-12 22:32pm
not any particular reason just i try to do it but i m getting help me.
Sergey Alexandrovich Kryukov 17-Nov-12 22:38pm
I cannot see any valid reason to use such thing. -- I advised what to do instead in my answer (it's in the links to my past answers).

I also explained how the problem with disposed forms is solved.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You cannot open (show; there is no "open") a form which was closed, because it is disposed. The most usual pattern here is to capture the attempt to close a form and cancel it, hiding it instead. To do so, you would need to either handle the event System.Windows.Forms.Form.FormClosing or override the virtual method System.Windows.Forms.Form.OnFormClosing. As you usually create a form class anyway, let's consider the second way:

public partial class MyForm // MyForm : System.Windows.Forms.Form shown in another part, usually auto-generated
    protected override OnFormClosing(FormClosingEventArgs e)
        if (e.CloseReason == System.Windows.Forms.CloseReason.UserClosing) // only for this reason 
            e.Cancel = true; // so it won't be actually closed

Please see:[^],[^],[^],[^].

Now, about MDI. Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. I can explain what to do instead.

Please see:[^],
How to Create MDI Parent Window in WPF?[^].

See also my past answers:
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

shambhoo kumar 17-Nov-12 22:46pm
Thanks alot sir.....
Sergey Alexandrovich Kryukov 17-Nov-12 22:51pm
My pleasure.
Good luck, call again.
shambhoo kumar 17-Nov-12 23:05pm
ya sir...
i wanna add to u in my facebook frnd so plz sent me your Facebook id.
Sergey Alexandrovich Kryukov 17-Nov-12 23:15pm
Do I look like the one who would use Facebook? :-)
shambhoo kumar 20-Nov-12 1:00am
But Why Not u use it...?
any reason....?
Reason? Not seeing a reason to use it... :-)
Why? Do you think I have nothing else to do? :-)
shambhoo kumar 20-Nov-12 1:13am
ha ha ha.......hmm....:)
this is funny.....:)
shambhoo kumar 20-Nov-12 10:55am
hello sir i m faceing a broblem so plz again u help question is
"how can open multy oledbdatareader at same time in window application."

plz u help me one's again.
Sergey Alexandrovich Kryukov 20-Nov-12 11:42am
This is a different question; you can post it separately; and I cannot promise to answer it. Make sure you provide sufficient detail and explain your goals.

Just a couple of notes: there is no such thing as "same time" -- there are asynchronous operations, where the order of execution is not determined, is random or pseudo-random, and the logical result of operations is not effected by the order of execution (otherwise it is called "racing condition" which can be defined as "incorrect dependency on the order of execution", a bad thing). If you need to asynchronously read database, you need to do it in two or more separate threads.

Probably you also need to understand transactions and transactional properties.

shambhoo kumar 20-Nov-12 12:00pm
exactly i want to say "in one open conection i want to open multy oledbDataReader".
Sergey Alexandrovich Kryukov 20-Nov-12 12:13pm
If you still have issue with that, please post a separate question.
shambhoo kumar 20-Nov-12 12:46pm
ok sir....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151125.3 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100