System.Windows.Forms.TreeNodeCollection.Add C# (CSharp) Method

Add() public method

public Add ( string text ) : TreeNode
text string
return TreeNode
        public virtual TreeNode Add(string text)
        {
            TreeNode node = new TreeNode(text);
            this.Add(node);
            return node;
        }

Same methods

TreeNodeCollection::Add ( string key, string text ) : TreeNode
TreeNodeCollection::Add ( TreeNode node ) : int

Usage Example

 /// <summary>
 /// 获取注册表项的子节点,并将其添加到树形控件节点中
 /// </summary>
 /// <param name="nodes"></param>
 /// <param name="rootKey"></param>
 public void GetSubKey(TreeNodeCollection nodes, RegistryKey rootKey)
 {
     if (nodes.Count != 0) return;
     //获取项的子项名称列表
     string[] keyNames = rootKey.GetSubKeyNames();
     //遍历子项名称
     foreach (string keyName in keyNames)
     {
     try
     {
     //根据子项名称功能注册表项
     RegistryKey key = rootKey.OpenSubKey(keyName);
     //如果表项不存在,则继续遍历下一表项
     if (key == null) continue;
     //根据子项名称创建对应树形控件节点
     TreeNode TNRoot = new TreeNode(keyName);
     //将注册表项与树形控件节点绑定在一起
     TNRoot.Tag = key;
     //向树形控件中添加节点
     nodes.Add(TNRoot);
     }
     catch
     {
     //如果由于权限问题无法访问子项,则继续搜索下一子项
     continue;
     }
     }
 }
All Usage Examples Of System.Windows.Forms.TreeNodeCollection::Add