Form Closes without this->close() being called

I have a form and when I click a button, the form closes even though I never call the close() function. The code is below:

if(group)
{
tree->Nodes->Add(textBox1->Text);
}
else
{
tree->Nodes[gIndex]->Nodes->Add(textBox1->Text);
}
textBox1->Clear();
textBox1->Focus();

that is all my button_click even does yet my form closes after the execution...why


Answer this question

Form Closes without this->close() being called

  • imaheshbabu

    I stepped through but it just executes to the end of the function and then returns back to the original form that called it. There is no specific line of code and I didn't see anything in the call stack that was suspicious.

  • RobKor

    What if you step on beyond there Obviously, nothing is going wrong within the call then.



  • eci

    sorry, my bad

  • Aravind779

    You're not checking that gIndex is a valid index, could that be the problem I'm thinking perhaps it's blowing up. Have you tried setting a break point and stepping through to see what happens



  • BJPHODGE

    Did you step through the code and work out what line was causing it to close

  • billoo

    That's cool. The behaviour is totally illogical and stupid IMO, I can't imagine why Microsoft offer it, and it's caused me no end of grief in the past.



  • bogdan_mabo

    The dialogResult property was set to cancel, I changed it to none and now it works. Not sure how it got set, or why it wasn't making a difference before but there's the answer.


    Thanks for all your help i appreciate it.

  • Steve Seeley

    I tried the try/catch with all exceptions but it didn't catch anything.

  • Bas Wildeman

    Ah - one really sucky thing in .NET is that if a form opens and it has a dialog result, and it's opened by a form that also has the dialog results set up, the parent form is also closed. That's probably what triggered this behaviour, although you didn't say you were opening a form



  • alphadog4

    I was thinking of a try/catch around the code, or going to your exceptions list and enabling all exceptions. Perhaps you're getting a quiet trap of an exception

    I've encountered this recently when a thread caused an exception and the thread quietly stopped running.

    Brian


  • Form Closes without this->close() being called