How to share the same window

BenTam-3003 686 Reputation points
2022-02-26T04:05:33.89+00:00

Dear All,

I have a form, StudentList.cs, that displays the names of all students. Users can double-click on a name of a single student to view the details of that student on another form. However, when the user double-clicks on the name of other students, a new form will be open. My question is how to automatically close the form of the prior student and display the details of another student in the same position. That is how to share the same window for all students' details.

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,681 Reputation points
    2022-02-26T14:09:49.977+00:00

    You can create the Form only if it does not exist yet
    Something like this =>

    178084-form-doubleclick.gif

        Student_Form form2 = null;  
    
        private void StudentList_dataListView_MouseDoubleClick(object sender, EventArgs e)  
        {  
            if (form2 == null || form2.IsDisposed)  
            {  
                form2 = new Student_Form();  
                form2.Owner = this;  
            }  
            // controls must be Public  
            form2.labelID.Text = dataListView1.SelectedItem.SubItems[0].Text;   
            form2.textBoxFirstName.Text = dataListView1.SelectedItem.SubItems[1].Text;  
            form2.textBoxLastName.Text = dataListView1.SelectedItem.SubItems[2].Text;  
            form2.textBoxLocation.Text = dataListView1.SelectedItem.SubItems[3].Text;  
            form2.Show();  
        }  
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.