zoukankan      html  css  js  c++  java
  • 关于地址添加 子窗体向父窗体传值 树的使用详细

    namespace ItcastSIMS
    {
        public partial class FrmArea : Form
        {
            public FrmArea()
            {
                InitializeComponent();
            }
            AreaBLL bll = new AreaBLL();
            List<Areas> list;//数据库地址信息
            private void FrmArea_Load(object sender, EventArgs e)
            {
                list = bll.GetAllAreas();
                tvAreas.Nodes.Clear();//默认节点清空
                CreateParent();
            }

            private void CreateParent()
            {
                TreeNode parent = new TreeNode();
                parent.Text = "全国";
                parent.Tag = 0;
                tvAreas.Nodes.Add(parent);//添加父节点

                //添加子节点
                CreateChild(parent);


                //展开
                //tvAreas.ExpandAll();
                parent.Expand();
            }
            
            private void CreateChild(TreeNode parent)
            {
                //父节点的id
                int pid = Convert.ToInt32(parent.Tag);

                foreach (Areas a in list)
                {
                    if (a.APid == pid)
                    {
                        TreeNode tn = new TreeNode();
                        tn.Text = a.AName;
                        tn.Tag = a.AID;
                        parent.Nodes.Add(tn);

                        //递归调用,加载子节点
                        CreateChild(tn);
                    }
                }
            }

            private void btnSure_Click(object sender, EventArgs e)
            {
                //获取选中的节点
                GetTNText(tvAreas.SelectedNode);
                txt += tvAreas.SelectedNode.Text;
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            public string txt = "";
            /// <summary>
            /// 获取选中节点的父节点的内容
            /// </summary>
            /// <param name="tn"></param>
            /// <returns></returns>
            void GetTNText(TreeNode tn)
            {
                if (tn.Parent != null)
                {
                    GetTNText(tn.Parent);
                    txt += tn.Parent.Text + "-";
                }
            }
        }

    }

    、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

     //选择地区
            private void btnChooseArea_Click(object sender, EventArgs e)
            {
                FrmArea frm = new FrmArea();

                if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    txtArea.Text = frm.txt;
                }
            }

  • 相关阅读:
    highcharts绘制股票k线
    利用meta标签将http请求换成https请求
    path.join 与 path.resolve 的区别
    【转】弧度和角度的转换
    块级元素和行内元素的区别 (block vs. inline)
    ubuntu下安装Apache + PHP + Mysql
    [读书笔记] CSS权威指南2: 结构和层叠
    [读书笔记] CSS权威指南1: 选择器
    [读书笔记] Head First 设计模式
    深入浅出React Native 3: 从零开始写一个Hello World
  • 原文地址:https://www.cnblogs.com/eric-gms/p/3453513.html
Copyright © 2011-2022 走看看