// It is used to collapse and expand the workspaces's associated folders // When we click on particular workspace control it pulls up the folder of that workspace // and show in the Tree view heirarchy void workspaceButtonHandler(object sender, EventArgs e) { Button clickedButton = (Button)sender; CustomWorkspacePanel clickedPanel = (CustomWorkspacePanel)((Button)sender).Parent; // check if the panel is already expanded, then clear all child if (clickedPanel.Controls.Count > 1) { clickedPanel.Controls.Clear(); clickedPanel.Controls.Add(clickedButton); } else if (clickedPanel.Controls.Count == 1) { var workspaceName = clickedButton.Text; UserWorkspaceDao workspaceDao = new UserWorkspaceDao(); UserWorkspace workspaceSelected = workspaceDao.getByName(workspaceName.Trim()); prepareTreeNodeHeirarchy(workspaceSelected.WorkspaceId); Panel childPanel = new Panel(); childPanel.AutoSize = true; childPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; childPanel.Dock = System.Windows.Forms.DockStyle.Top; childPanel.Location = new System.Drawing.Point(0, 0); childPanel.Name = "childPanel"; childPanel.Size = new System.Drawing.Size(200, 104); childPanel.TabIndex = 1; childPanel.BackColor = System.Drawing.Color.WhiteSmoke; childPanel.Controls.Add(myCustomTreeView); clickedPanel.Controls.Add(childPanel); clickedPanel.Controls.Add(clickedButton); } }