Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
1.00/5 (1 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:

C#
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
Comments
Sergey Alexandrovich Kryukov 2-Jan-13 19:05pm    
Everything goes wrong. You trying to show a form which is already showing. Wow!
—SA

C#
if( newMakeForm.Visible ) 
{ 
   newMakeForm.ActiveForm.Visible = false; 
}
newMakeForm.ActiveForm.ShowDialog();
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 2-Jan-13 19:04pm    
Perfectly formal answer which makes no practical sense at all. After some thinking, I decided to vote 5... :-)
—SA
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?
 
Share this answer
 
Comments
Aarti Meswania 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900