zoukankan      html  css  js  c++  java
  • TreeView的递归读取

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace CTERP
    {
        
    public partial class FrmSysFunctionMenu : Form
        {
            
    public FrmSysFunctionMenu()
            {
                InitializeComponent();
            }

            LinkDataBase link 
    = new LinkDataBase();
            DataSet dsFunctionMenu 
    = null;
            
    private void FrmFunctionMenu_Load(object sender, EventArgs e)
            {
                dsFunctionMenu 
    = new DataSet();
                tvFunctionMenu.Nodes.Add(
    "ERP系统功能菜单");
                TreeNode rootNode 
    = tvFunctionMenu.Nodes[0];
                CreateChildTree(
    -1, rootNode);
                rootNode.Expand();
    //展开根结点
            }

            
    //递归调用创建子树
            private void CreateChildTree(int nparentid, TreeNode currentNode)
            {
                
    using (SqlConnection sqlCONN = new SqlConnection("server=.;uid=sa;database=cterp"))
                {
                    
    string strSelect = "select id,title,parentid,sortid from sy_menu_wds where parentid=" + nparentid + " order by sortid";
                    SqlCommand sqlCMD 
    = new SqlCommand(strSelect);
                    sqlCMD.Connection 
    = sqlCONN;
                    sqlCONN.Open();
                    
    using (SqlDataReader sqlDR = sqlCMD.ExecuteReader())
                    {
                        
    while (sqlDR.Read())
                        {
                            TreeNode node 
    = new TreeNode(sqlDR["title"].ToString().Trim());
                            CreateChildTree(
    int.Parse(sqlDR["id"].ToString().Trim()), node);  //递归出子节点 
                            currentNode.Nodes.Add(node);
                        }
                    }
                } 
            }

        }
    }
  • 相关阅读:
    6-5 函数
    6-2 触发器
    4、MongoDB学习之备份还原
    3、MongoDB学习之固定集合
    2、MongoDB学习之索引的管理
    1、MongoDB学习之基本操作
    JS-01
    | 和 ||,& 和 && 的区别
    正则
    设计测试用例的经验总结
  • 原文地址:https://www.cnblogs.com/perfect/p/961434.html
Copyright © 2011-2022 走看看