zoukankan      html  css  js  c++  java
  • win form treeview添加节点

    //实例代码:

    /// <summary>
    /// 添加节点事件
    /// </summary>
    /// <param name="tnodes"></param>
    /// <param name="nodeName">父节点名称</param>
    /// <param name="subNodeName">添加的节点名称</param>
    /// <param name="key"></param>
    /// <returns></returns>
    private string AddNodes(TreeNodeCollection tnodes, string nodeName, string subNodeName, string key = "")
    {
    string Msg = string.Empty;
    foreach (TreeNode node in tnodes)
    {
    if (node.Text == nodeName)
    {
    int tag = -1;
    GetNodes(node.Nodes, subNodeName, out tag);
    if (tag == 1)
    {
    //给指定的节点增加子节点
    node.Nodes.Add(key, subNodeName);
    Msg = "添加成功";
    break;
    }
    else
    {
    Msg = "该节点下已存在此子节点";
    }
    }
    //ShowNodes(node.Nodes,nodeName,subNodeName);
    }
    return Msg;
    }

    /// <summary>
    /// 查找指定节点是否包含某个子节点
    /// </summary>
    /// <param name="tnodes"></param>
    /// <param name="nodeName"></param>
    /// <param name="tag">有返回0 无返回1</param>
    /// <returns></returns>
    private TreeNode GetNodes(TreeNodeCollection tnodes, string nodeName, out int tag)
    {
    foreach (TreeNode node in tnodes)
    {
    if (node.Text == nodeName)
    {
    tag = 0;
    return node;
    }
    }
    tag = 1;
    return new TreeNode();
    }

  • 相关阅读:
    04_远程管理常用命令
    03_文件和目录常用命令
    02_Linux 终端命令格式
    01_常用 Linux 命令的基本使用
    test
    centOS 7 更改root密码
    安装 centos7
    1
    IO模型
    使用git连接到Github
  • 原文地址:https://www.cnblogs.com/xiewei123/p/10902434.html
Copyright © 2011-2022 走看看