• 关于地址添加 子窗体向父窗体传值 树的使用详细


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

  • 相关阅读:
    TransactionScope和Enterprise Libray 3.0 Data Access Application Block
    C#之父 Anders Hejlsberg
    openSUSE Linux 10.2 多语言版
    承蒙各位朋友支持与厚爱,荣获asp.net MVP荣誉
    如何在ASP.NET 2.0中定制Expression Builders
    检查Python对象
    IronPython中使用Cecil类库指南
    MSDN Magazine 4月份asp.net文章
    Reflector 插件
    WSS v3的Form身份认证
  • 原文地址:https://www.cnblogs.com/eric-gms/p/3453513.html
Copyright © 2020-2023  润新知