Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi everyone! I have a quick question regarding the ShowDialog method. I have a second form that I want to be shown upon a button click. I have this method so far:
 
private void insertMakeButton_Click(object sender, EventArgs e)
        {
            newMakeForm.ActiveForm.ShowDialog();
        }
 

The error I'm getting when I click on the corresponding button is:
Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling showDialog.
 
Can someone shed some light as to what I'm doing wrong?
 
Thanks everyone!
Posted 2-Jan-13 6:57am
Comments
Sergey Alexandrovich Kryukov at 2-Jan-13 19:05pm
   
Everything goes wrong. You trying to show a form which is already showing. Wow!
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

if( newMakeForm.Visible ) 
{ 
   newMakeForm.ActiveForm.Visible = false; 
}
newMakeForm.ActiveForm.ShowDialog();
  Permalink  
v2
Comments
Sergey Alexandrovich Kryukov at 2-Jan-13 19:04pm
   
Perfectly formal answer which makes no practical sense at all. After some thinking, I decided to vote 5... :-)
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is not clear to me can please clerify below:
1. Where is the insertMakeButton, on second form or in some other form?
2. Is Second form object already created in the aaplication or not?
  Permalink  
Comments
Aarti Meswania at 3-Jan-13 3:15am
   
use "Have a Question or comment" button to contact the person who answer your question.
 

and which is the form name you want to open?
and in which form you have taken button insertMakeButton
give names of forms
joshrduncan2012 at 3-Jan-13 17:52pm
   
The insertButton is on the original form and the newMakeForm is the 2nd form. I want the text on newMakeForm to be added to the comboBox on the original form.

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

  Print Answers RSS
0 OriginalGriff 540
1 Sergey Alexandrovich Kryukov 432
2 Yogesh Kumar Tyagi 384
3 Prakriti Goyal 280
4 Maciej Los 205
0 OriginalGriff 6,472
1 Sergey Alexandrovich Kryukov 5,404
2 Maciej Los 3,434
3 Peter Leow 3,259
4 DamithSL 2,495


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
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