3

My problem is that I want to be able to set certain nodes invisible. I've got two forms. The second one is filled witch checkboxes named same as nodes in first form. After checking one of checkboxes I want to make this node in first form invisible. Passing data between forms works, because I tested it with MessageBox.

Code from second form (Responslibe for making nodes invisible):

        private void button1_Click(object sender, EventArgs e)
    {
        if (checkBox1.Checked == true)
        {
            Form1.a = true;
        }


        this.Close();
    }

Code from first form that contains nodes:

    public static bool a;
    public static bool b;

    private void Categories()
    {
        if(a == true)
            {
                treeView1.Nodes[0].IsVisible = false;
            }

    }

Error that I get:

Property or indexer 'System.Windows.Forms.TreeNode.IsVisible' cannot be assigned to -- it is read only
PotatoBox
  • 583
  • 2
  • 10
  • 33

1 Answers1

4

Instead of making tree node invisible. I think you should remove it from the collection when you don't want to display it and you have to add it again if you want to show it.

You can use Remove function to remove the node

tree.Nodes.Remove(myNode);

You can try something like this

private void Categories()
{
  if(a == true)
  {
    treeView1.Nodes[0].Remove();
   }
}
Sachin
  • 40,216
  • 7
  • 90
  • 102
  • 2
    That is true. You should remove it if you want to hide it and restore it later if you want to show it again. – Jay Patel Jul 17 '13 at 21:06