How to open multiple forms in C #?

I have a DataGridView with data loaded from a database. Each row has a View button, and when I click on it, another form opens with specific information, but the main form with the DataGridView still opens. I am doing this with this code:

FormView fr = new FormView(id);
fr.ShowDialog();

The problem is that I cannot open multiple FormViews at the same time, because the focus is still in the first open FormView. How can i do this?

+5
source share
4 answers

when you use ShowDialog in the form that it shows and is waiting for an answer like DialogeResult, but when you just need to show the form and don't need any response, you can just call form.Show ()
here is the code:

:

Form f = new Form(); 
DialogResult res = f.ShowDialog();  

//code stops here until you return something of type DialogResult  
if (res == System.Windows.Forms.DialogResult.OK)  
    I_Will_Run_Just_When_DialogReult_Returned_Is_OK();  

:

f.Show();  
I_Will_Run_Anyway_Right_After_Showing_Form(); 
+4

ShowDialog , , ShowDialog , .

fr.Show.

+2

You need to do:

FormView fr = new FormView(id);  
fr.Show();

to show them is not modal, so execution can continue and allows you to show more.

0
source

You can change this

fr.ShowDialog();

to

fr.Show();
0
source

All Articles