关闭

一个用C#写的无限结点树的原码

标签: cdatasetwebservicestringnull
1092人阅读 评论(0) 收藏 举报
分类:

一个用C#写的无限结点树的原码
  //递归生成树的项目
  private void CreateNode(int sZml,Crownwood.DotNetMagic.Controls.Node pNode)
  {
   //从WebService上取得数据集====================================================
   DataSet myDataSet=new DataSet();
   
   string strCom = "SELECT * FROM cptree where zcpsid=" + sZml;
   myDataSet=Form1.myService.GetTree(strCom);
   //============================================================================
   pNode.Expanded=true;
   if(pNode.Expanded==false)
    pNode.Image=imageList.Images[7];
   else
    pNode.Image=imageList.Images[8];
   

   //定义一个DataRow
   System.Data.DataTable myDataTable=new DataTable(); //定义一个DataTable
   myDataTable = myDataSet.Tables["cptree"]; //引用DataSet中的一个DataTable
   foreach(System.Data.DataRow myDataRow in myDataTable.Rows)
   {

    if(pNode==null)
    {
     Crownwood.DotNetMagic.Controls.Node Nodee;
     Nodee=new Node();
     Nodee.Text=myDataRow["cplm"].ToString();
     Crownwood.DotNetMagic.Controls.Node Node = TheTreeCkCpXs.Nodes.Add(Nodee);
     CreateNode(Int32.Parse(myDataRow["cpsid"].ToString()),Node);    //再次递归
    }
    else
    {
     Crownwood.DotNetMagic.Controls.Node Nodee;
     Nodee=new Node();
     Nodee.Text=myDataRow["cplm"].ToString();
     Crownwood.DotNetMagic.Controls.Node Node =  pNode.Nodes.Add(Nodee);
     CreateNode(Int32.Parse(myDataRow["cpsid"].ToString()),Node);    //再次递归
    }
   }
  
  }

 

//加载树
  private void CreateTree()
  {
   //改变主窗口菜单的属性

   // Create the TreeControl for use in the new docking window
   TheTreeCkCpXs.Dock=DockStyle.Left;
   TheTreeCkCpXs.SetTreeControlStyle(TreeControlStyles.GroupOfficeLight);
   TheTreeCkCpXs.BorderStyle = TreeBorderStyle.None;
   TheTreeCkCpXs.Location = new System.Drawing.Point(0, 0);
   TheTreeCkCpXs.GroupColoring = GroupColoring.Office2003Light;
   TheTreeCkCpXs.Width=160;
   TheTreeCkCpXs.SetTreeControlStyle(TreeControlStyles.StandardPlain);
   TheTreeCkCpXs.AutoEdit = false;
   TheTreeCkCpXs.PathSeparator=",";
   Crownwood.DotNetMagic.Controls.Node Node1;
   int sIndex;
   Node1=new Node();
   //   Form1 theForm1 = new Form1();
   Node1.Text=Form1.ymmc;
   TheTreeCkCpXs.Nodes.Add(Node1);
   TheTreeCkCpXs.SelectedNode=Node1;
   sIndex=TheTreeCkCpXs.Nodes.IndexOf(Node1);
   CreateNode(0,Node1);
   Controls.Add(TheTreeCkCpXs);
  }

数据表格式
3 cpsid int 4 0
0 cplm nvarchar 50 1
0 zcpsid nvarchar 50 1
0 cpscp tinyint 1 1

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:19728次
    • 积分:366
    • 等级:
    • 排名:千里之外
    • 原创:16篇
    • 转载:0篇
    • 译文:0篇
    • 评论:7条
    文章分类
    最新评论