• 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);
                        }
                    }
                } 
            }

        }
    }
  • 相关阅读:
    Bootstrap4(28): 滚动监听(Scrollspy)
    Bootstrap4(27): 弹出框
    Bootstrap4(26): 提示框
    Bootstrap4(25): 模态框
    Bootstrap4(24): 轮播
    Bootstrap4(23): 自定义表单
    Bootstrap4(22): 输入框组
    Bootstrap4(21): 表单控件
    Bootstrap4(20): 表单
    Bootstrap4(19): 面包屑导航(Breadcrumb)
  • 原文地址:https://www.cnblogs.com/perfect/p/961434.html
Copyright © 2020-2023  润新知