zoukankan      html  css  js  c++  java
  • c# TreeView

    树形绑定数据

    SQL语句:提出需要绑定的父节点和子节点的数据语句,一般包括要显示的数据和主键ID。

    如:

    (父节点)

     if @type='dep'
     begin
     select departmentName, departmentId  from wb_department
     end
     (子节点)
     if @type='pro'
     begin
     select professionId,professionName,departmentId  from wb_profession
     end

     

     

    c#代码

    public DataSet ds = new DataSet();

     protected void Page_Load(object sender, EventArgs e)  

       {        

       ds.Tables.Add(Class1.dep());        

      ds.Tables[0].TableName = "depTable";        

      ds.Tables.Add(Class1.pro());        

      ds.Tables[1].TableName = "proTable";       

        ds.Relations.Add("dep_pro", ds.Tables[0].Columns["departmentId"], ds.Tables[1].Columns["departmentId"]);

     

         foreach (DataRow FatherRow in ds.Tables[0].Rows)     

        {           

        TreeNode FatherNode = new TreeNode((string)FatherRow["departmentName"]);            

       //asp.net中c#语句是这样: FatherNode.Target = FatherRow["departmentId"].ToString();

        FatherNode.Tag = FatherRow["departmentId"].ToString();           

        TreeView1.Nodes.Add(FatherNode);

            foreach (DataRow ChildrenRow in FatherRow.GetChildRows("dep_pro"))            

       {                

        TreeNode ChildrenNode = new TreeNode((string)ChildrenRow["professionName"]);                

        //ChildrenNode.Target = ChildrenRow["professionId"].ToString();

            ChildrenNode.Tag= ChildrenRow["professionId"].ToString();                

        //FatherNode.ChildNodes.Add(ChildrenNode);            

        FatherNode.Nodes.Add(ChildrenNode);  

       }

        }    

    }

    动态添加父节点

    TreeNode node = new TreeNode();            

    node.Text = textBox1.Text.ToString();            

    this.treeView1.Nodes.Add(node);

    TreeNode node1 = new TreeNode();            

    this.treeView1.Nodes[0].Nodes.Add(node1);

    TreeView-----节点单击事件:

    private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
            {
                Form form2 = new Form();
                form2.ShowDialog();
            }

     


     

  • 相关阅读:
    安卓使用spinner控件和pull解析实现全国省市县的三级联动(附上xml文件)
    安卓linearlayout布局的一个嵌套实例
    接口回调的例子和安卓中的接口回掉实例
    Android Studio 快捷键
    java比较器 之compareable 和comparato比较
    4.Gradle构建Spring Boot项目
    2.Gradle安装和常用命令
    1.Gradle基础介绍
    6.SpringBoot学习(六)——Spring Boot Banner自定义
    4.SpringBoot学习(四)——Spring Boot Validation校验及原理
  • 原文地址:https://www.cnblogs.com/dieaz5/p/2585234.html
Copyright © 2011-2022 走看看