2013-07-17 29 views
3

我的問題是我想能夠設置某些節點不可見。我有兩種形式。第二個填充女巫複選框與第一種形式的節點相同。在選中其中一個複選框後,我想讓這個節點以第一種形式隱形。在表單之間傳遞數據是可行的,因爲我使用MessageBox對其進行了測試。使某個節點不可見

從第二種形式的代碼(Responslibe製作節點隱形):從第一種形式

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


     this.Close(); 
    } 

代碼包含節點:

public static bool a; 
    public static bool b; 

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

    } 

錯誤,我得到:

Property or indexer 'System.Windows.Forms.TreeNode.IsVisible' cannot be assigned to -- it is read only 
+1

東西因爲'IsVisible'是一個只讀屬性。 –

+0

可能的重複http://stackoverflow.com/questions/1199417/how-do-i-make-a-treenode-not-visible-c –

回答

4

而不是讓樹節點不可見。我想你應該從集合中刪除它,當你不想顯示它,如果你想顯示它,你必須重新添加它。

您可以使用刪除功能刪除節點

tree.Nodes.Remove(myNode); 

你可以嘗試這樣的

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

好吧,但我會失去每個孩子的節點,對吧? – PotatoBox

+2

這是真的。如果要隱藏它,並且如果想要再次顯示它,請稍後恢復。 –