TreeNodeCollection.IsReadOnly 属性

定义

获取一个值,该值指示集合是否为只读。

public:
 property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean

属性值

Boolean

如果该集合为只读,则为 true;否则为 false。 默认值为 false

实现

示例

下面的代码示例从一个树节点中删除所选树节点,如果两个 TreeView 树节点集合不是只读的,则将其添加到另一个节点。 单击 a Button 时,TreeNode将使用Remove该方法从一个属性中删除该属性的表示TreeView.SelectedNode,并使用该方法添加到另一TreeViewTreeViewInsert属性。 此示例要求你有一个包含两TreeViewForm控件和一个Button控件。 TreeView控件应命名treeView1treeView2

void button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   // If neither TreeNodeCollection is read-only, move the
   // selected node from treeView1 to treeView2.
   if (  !treeView1->Nodes->IsReadOnly &&  !treeView2->Nodes->IsReadOnly )
   {
      if ( treeView1->SelectedNode != nullptr )
      {
         TreeNode^ tn = treeView1->SelectedNode;
         treeView1->Nodes->Remove( tn );
         treeView2->Nodes->Insert( treeView2->Nodes->Count, tn );
      }
   }
}
private void button1_Click(object sender, EventArgs e)
{
   // If neither TreeNodeCollection is read-only, move the 
   // selected node from treeView1 to treeView2.
   if(!treeView1.Nodes.IsReadOnly && !treeView2.Nodes.IsReadOnly)
   {
      if(treeView1.SelectedNode != null)
      {
         TreeNode tn = treeView1.SelectedNode;
         treeView1.Nodes.Remove(tn);
         treeView2.Nodes.Insert(treeView2.Nodes.Count, tn);
      }
   }
}
Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
   ' If neither TreeNodeCollection is read-only, move the 
   ' selected node from treeView1 to treeView2. 
   If Not treeView1.Nodes.IsReadOnly And Not treeView2.Nodes.IsReadOnly Then
      If (treeView1.SelectedNode IsNot Nothing) Then
         Dim tn As TreeNode = treeView1.SelectedNode
         treeView1.Nodes.Remove(tn)
         treeView2.Nodes.Insert(treeView2.Nodes.Count, tn)
      End If
   End If
End Sub

适用于