winforms panel hide and show

I have two panels occupying the same space in one side of a splitviewcontainer. I want to dynamically show or hide one panel or the other.

Approaches I've tried so far are:

if (treeView1.SelectedNode.Name.Contains("cat")) {
    foreach (Control control in menuItemPanel.Controls)
    menuItemPanel.Visible = false;

    categoryPanel.Visible = true;
    foreach (Control control in categoryPanel.Controls)

    // ...

and the converse for the else case. None of these seem to work. That is the categoryPanel is shown when a category node is selected, but the screen shows blank space when a menuItem node is selected.

What am I doing wrong?


The code doesn't make much sense, re-ordering the controls in the panels is not what you want to do. Also sounds that the code in the else clause is failing, code you didn't post. Do it like this instead (a guess):

bool categorySelected = treeView1.SelectedNode.Name.Contains("cat");
menuItemPanel.Visible = !categorySelected;
categoryPanel.Visible = categorySelected;

Need Your Help

Open/unrestricted attribute list for an element in a DTD?

xml dtd

Is it possible, within a DTD, to define an element to have an open/unrestricted attribute list?

Neo4j Client: Can we throw an exception if there are already maxium number of relationship reached?

constraints relationship neo4jclient

If I have a one to many relationship like 1 Vehicle has 1 to 4 wheels, if someone try to call

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.