zoukankan      html  css  js  c++  java
  • 绑定树控件

    #region 绑定树控件
    bool[] islastNode;
    /// <summary>
    /// 添加监控点
    /// </summary>
    /// <param name="node"></param>
    /// <param name="control"></param>
    /// <param name="parent_id"></param>
    private void AddTreeView(TreeNode node, control_unit[] control, int parent_id)
    {
    for (int i = 0; i < control.Length; i++)
    {
    if (control[i].Parent_id == parent_id)
    {
    TreeNode nextnode = new TreeNode();
    nextnode.Name = control[i].Control_unit_id.ToString();
    nextnode.Text = control[i].Name;
    if (islastNode[i])
    {
    //加载设备
    getDevice(control[i].Control_unit_id, nextnode);
    }
    else
    {
    //加载字项
    AddTreeView(nextnode, control, control[i].Control_unit_id);
    }
    node.Nodes.Add(nextnode);
    }
    }
    }
    /// <summary>
    /// 加载设备
    /// </summary>
    /// <param name="control_unit_id"></param>
    /// <param name="parentNode"></param>
    private void getDevice(int control_unit_id, TreeNode parentNode)
    {
    if (Service.Common.device != null && Service.Common.device.Length > 0)
    {
    for (int i = 0; i < Service.Common.device.Length; i++)
    {
    if (Service.Common.device[i].Control_unit_id == control_unit_id)
    {

    TreeNode divenode = new TreeNode();
    divenode.Name = Service.Common.device[i].Device_id.ToString();
    divenode.Text = Service.Common.device[i].Name;
    //加载摄像头
    if (Service.Common.camera != null && Service.Common.camera.Length > 0)
    {
    for (int k = 0; k < Service.Common.camera.Length; k++)
    {
    TreeNode cameranode = new TreeNode();
    cameranode.Name = Service.Common.camera[k].Camera_id.ToString();
    cameranode.Text = Service.Common.camera[k].Name;
    divenode.Nodes.Add(cameranode);
    }
    }
    parentNode.Nodes.Add(divenode);
    }
    }
    }
    }
    /// <summary>
    /// 树形目录
    /// </summary>
    private void loadTreeView(TreeView tree)
    {
    //DataService.control_unit[] control = Service.Common.data.getControl_list(-1, -1);
    islastNode = new bool[Service.Common.control.Length];
    //找出没有子项的借点
    for (int i = 0; i < Service.Common.control.Length; i++)
    {
    islastNode[i] = true;
    for (int j = Service.Common.control.Length - 1; j >= 0; j--)
    {
    if (Service.Common.control[i].Control_unit_id == Service.Common.control[j].Parent_id)
    {
    islastNode[i] = false;
    }
    }
    }
    for (int i = 0; i < Service.Common.control.Length; i++)
    {
    if (Service.Common.control[i].Parent_id == 0)
    {
    TreeNode node = new TreeNode();
    node.Name = Service.Common.control[i].Control_unit_id.ToString();
    node.Text = Service.Common.control[i].Name;
    if (islastNode[i])
    {
    //加载设备
    getDevice(Service.Common.control[i].Control_unit_id, node);
    }
    else
    {
    //加载字项
    AddTreeView(node, Service.Common.control, Service.Common.control[i].Control_unit_id);
    }
    tree.Nodes.Add(node);
    }
    }
    }
    #endregion

  • 相关阅读:
    python入门6 字符串拼接、格式化输出
    python入门5 运算符
    python入门3 python变量,id(),is运算符
    python入门2 python字符串换行显示、字符串太长连接多行
    python入门1 python手动编译py_compile,compileall
    测试笔记:jsonp跨域接口测试
    Jmeter入门16 数据构造之随机数Random Variable & __Random函数
    Jmeter入门15 JSON Assertion 适用于json格式的响应断言
    openshift 配置ldap认证
    openshift node资源限制
  • 原文地址:https://www.cnblogs.com/lmcblog/p/2597821.html
Copyright © 2011-2022 走看看