有一个表  SMID 编号,ParentNum 介绍人编号(取SMID的值),Grade 级别
SMID ParentNum Grade
001        0       1
002        001     2
003        002     3
004        002     3
005        003     4
006        004     4根据Grade实现树形图
比如:SMID 002 他的介绍人编号是ParentNum 001 ,他就是 001 的子级,形成这样的树形图
--001
    --002
       --003
          --005
       --004
          --006
请高手多多帮忙啊 
50分题啊

解决方案 »

  1.   

    TreeNode parentnd = new TreeNode();
                parentnd.Tag = ProjectID;
                parentnd.Text = ProjectName;
                this.treeView1.Nodes.Add(parentnd);            DsNode = SqlCeHelper.GetDataSet("select SMID , ParentNum  from SMID ");
                System.Data.DataRow[] DrNode = DsNode.Tables[0].Select(" ParentNum ='0'");
                for (int i = 0; i < DrNode.Length; i++)
                {
                    TreeNode nd = new TreeNode();
                    nd.Tag = DrNode[i]["SMID "].ToString();
                    nd.Text = DrNode[i]["ParentNum  "].ToString();
                    parentnd.Nodes.Add(nd);
                    GetChilden(nd, DsNode);                                
                  }
                this.treeView1.EndUpdate();        private void GetChilden(TreeNode parentTreeNode, DataSet DsNode)
            {            System.Data.DataRow[] DrChildenNode = DsNode.Tables[0].Select(" ParentNum  ='" + parentTreeNode.Tag + "'");
                for (int i = 0; i < DrChildenNode.Length; i++)
                {
                    string stateName = "";
                    TreeNode nd = new TreeNode();
                    nd.Tag = DrChildenNode[i]["SMID"].ToString();
                    nd.Text = DrChildenNode[i]["ParentNum"].ToString();                parentTreeNode.Nodes.Add(nd);                GetChilden(nd, DsNode);
                 }这个是根据你的要求写的,呵呵,不测试过,大致是这样,如果不对自己修改,呵呵,给分!!!