Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Plzzzzzzzzzzzzzzzzzzzzzzzzzz Help in form closing

Plzzzzzzzzzzzzzzzzzzzzzzzzzz Help in form closing

Scheduled Pinned Locked Moved C#
data-structureshelptutorialquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EEmaan
    wrote on last edited by
    #1

    Hi! i want to close windows form when i click on any tree node. when i click a tree node, after_select event of tree node is called and in that After_select event i closed my current web form and opened new form but it throws following exception. Disposed object of tree view could not be found. I posted this question two times before also but no satisfactory answer is given. One of member suggested to use IDisposal but i m not getting how to use it. So, can anyone suggest me the solution in detailed form. Thanx

    C 1 Reply Last reply
    0
    • E EEmaan

      Hi! i want to close windows form when i click on any tree node. when i click a tree node, after_select event of tree node is called and in that After_select event i closed my current web form and opened new form but it throws following exception. Disposed object of tree view could not be found. I posted this question two times before also but no satisfactory answer is given. One of member suggested to use IDisposal but i m not getting how to use it. So, can anyone suggest me the solution in detailed form. Thanx

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      EEmaan wrote:

      One of member suggested to use IDisposal but i m not getting how to use it

      IDisposable won't help here, the issue is precisely that you close the form while some code is running, and so the control is disposed while you're trying to use it. You're closing web forms ? Not windows forms ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      E 1 Reply Last reply
      0
      • C Christian Graus

        EEmaan wrote:

        One of member suggested to use IDisposal but i m not getting how to use it

        IDisposable won't help here, the issue is precisely that you close the form while some code is running, and so the control is disposed while you're trying to use it. You're closing web forms ? Not windows forms ?

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        E Offline
        E Offline
        EEmaan
        wrote on last edited by
        #3

        Sorry i wrote Web Form instead of Windows form. Actually i m closing windows form by using this.close(); my piece of code is like private void TreeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { Form2 f=new Form2(); f.show(); this.close(); } now plz give me its solution also.

        A C C 3 Replies Last reply
        0
        • E EEmaan

          Sorry i wrote Web Form instead of Windows form. Actually i m closing windows form by using this.close(); my piece of code is like private void TreeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { Form2 f=new Form2(); f.show(); this.close(); } now plz give me its solution also.

          A Offline
          A Offline
          Arun Immanuel
          wrote on last edited by
          #4

          I do not know the exact solution: But, see if this helps U. Locate the line "Application.Run(new Form1());" and enclose it within try catch. try { Application.Run(new Form1()); } catch(Exception exe) { }

          Regards, Arun Kumar.A

          C 1 Reply Last reply
          0
          • E EEmaan

            Sorry i wrote Web Form instead of Windows form. Actually i m closing windows form by using this.close(); my piece of code is like private void TreeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { Form2 f=new Form2(); f.show(); this.close(); } now plz give me its solution also.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            OK, I remember this. I told you days ago what to do. You can't do this. Because, when you close this form, you cause the Form2 instance to also be closed/disposed. Instead, make form1 and form2 user controls, put them both on the one form, and switch between them. Also, for goodness sakes, use real variable names and not TreeView1 and Form2.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            E 1 Reply Last reply
            0
            • A Arun Immanuel

              I do not know the exact solution: But, see if this helps U. Locate the line "Application.Run(new Form1());" and enclose it within try catch. try { Application.Run(new Form1()); } catch(Exception exe) { }

              Regards, Arun Kumar.A

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Gosh - it's pretty obvious what's going wrong.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              1 Reply Last reply
              0
              • C Christian Graus

                OK, I remember this. I told you days ago what to do. You can't do this. Because, when you close this form, you cause the Form2 instance to also be closed/disposed. Instead, make form1 and form2 user controls, put them both on the one form, and switch between them. Also, for goodness sakes, use real variable names and not TreeView1 and Form2.

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                E Offline
                E Offline
                EEmaan
                wrote on last edited by
                #7

                sorry i m not getting u if u can please follow the following link MBR IT-_NET 247 TreeView and ObjectDisposedException on microsoft_public_dotnet_framework_windowsforms.htm its seems that it is giving me the exact solution of my problem .I did it also but ite not working. Can u guide after viewing this page that what to do. Thanx alot for ur replies

                C 1 Reply Last reply
                0
                • E EEmaan

                  sorry i m not getting u if u can please follow the following link MBR IT-_NET 247 TreeView and ObjectDisposedException on microsoft_public_dotnet_framework_windowsforms.htm its seems that it is giving me the exact solution of my problem .I did it also but ite not working. Can u guide after viewing this page that what to do. Thanx alot for ur replies

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  That's not a link. What the page you hoped to link to says does not matter. What you're doing is wrong. Create user controls, lay them out to be your two forms. Put them both on the one form, and then make only one of them visible at a time.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                  1 Reply Last reply
                  0
                  • E EEmaan

                    Sorry i wrote Web Form instead of Windows form. Actually i m closing windows form by using this.close(); my piece of code is like private void TreeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { Form2 f=new Form2(); f.show(); this.close(); } now plz give me its solution also.

                    C Offline
                    C Offline
                    ChandraRam
                    wrote on last edited by
                    #9

                    EEmaan wrote:

                    Form2 f=new Form2();

                    You are creating this object within the original form (where the TreeView1 is)... it is available only within the After_Select event. When you close a form, all objects that are part of that form are destroyed and references to those will no longer be valid. Hope this helps.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups