Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make a desktop application using treeview and Panel it works fine a bit. But when i try to does not change like for instance, if i click Account opening, it opens the form, but if i click to go to a different form inside the application it doesnt change , you have to restart the form again to move to another form inside the main application My source code looks like this :

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
    switch (e.Node.Text)
    {
        case "Account Opening":
            f = new AccountOpening();
            f.TopLevel = false;
            this.panel1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
            f.Show();
            break;

        case "Check Balance":
            f = new CheckBalance();
            f.TopLevel = false;
            this.panel1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
            f.Show();
            break;

        case "Deposit":
            f = new Deposit();
            f.TopLevel = false;
            this.panel1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
            f.Show();
            break;

        case "Loan Repayment":
            f = new LoanRepayment();
            f.TopLevel = false;
            this.panel1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
            f.Show();
            break;


        case "Transfers":
            f = new Transfers();
            f.TopLevel = false;
            this.panel1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
            f.Show();
            break;

        case "Withdrawal":
            f = new Withdrawal();
            f.TopLevel = false;
            this.panel1.Controls.Add(f);
            f.Dock = DockStyle.Fill;
            f.Show();
            break;
    }
}


Apparently what am i missing?

What I have tried:

I have used If and simple switch case, doesnt seem to work as i expect
Posted
Updated 8-Jan-18 20:40pm
Comments
Hermann Jung 9-Jan-18 2:37am    
Do you ever remove the old control before adding a new one to panel1.Controls?

1 solution

Using Treeview & Panel control in Windows Form[^]

If this helps please vote for the solution
 
Share this answer
 

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