• TreeView 控件应用


    1、 (数据库设计如上)

    2、代码:       

            private void SetArea()
            {
                DataTable dt = new DataTable();
                dt = customer.GetArea();
                DataView dv = dt.DefaultView;
                DataTable dtProvince = dv.ToTable(true, "province", "provinceid");
                for (int i = 0; i < dtProvince.Rows.Count; i++)
                {
                    TreeNode nd = new TreeNode();
                    nd.Tag = dtProvince.Rows[i]["provinceid"].ToString();
                    nd.Text = dtProvince.Rows[i]["province"].ToString();
                    TreeArea.Nodes.Add(nd);
                    //插入子节点
                    CreateTreeNode(ref nd, dt);
                    TreeArea.ExpandAll();
                    TreeArea.CheckBoxes = true;
                }
            }
            private void CreateTreeNode(ref TreeNode tnParent, DataTable dt)
            {
                DataRow[] drArr = dt.Select("provinceid = '" + tnParent.Tag + "'");
                if (drArr.Length == 0) return;

                for (int i = 0; i < drArr.Length; i++)
                {
                    DataRow row = drArr[i];
                    TreeNode nd = new TreeNode();
                    nd.Tag = row["purchaseid"].ToString();
                    nd.Text = row["areaname"].ToString();
                    tnParent.Nodes.Add(nd);
                    CreateTreeNode(ref nd, dt);
                }


            }

    3、运行结果:

  • 相关阅读:
    ZYB建围墙
    换根DP
    原码,反码,补码的计算
    字符串游戏-博弈论-trie
    【十连赛day8】神炎皇
    生成序列
    【USACO 2006 February Silver】产奶安排Stall Reservations-贪心
    tar 压缩解压命令
    java 注解
    回溯算法解决全排列问题
  • 原文地址:https://www.cnblogs.com/leischen/p/2315833.html
Copyright © 2020-2023  润新知