cs bs的都可以

解决方案 »

  1.   

    http://www.microsoft.com/china/msdn/archives/library/dnaspp/html/aspnet-usingtreeviewiewebcontrol.asp#aspnet-usingtreeviewiewebcontrol_topic2
      

  2.   

    private void FlagRebuild()
    {

    tv_Flag.Nodes.Clear();
    BLL.M_Module BEA = new BLL.M_Module();
    DataSet ds = BEA.GetList(); AddTree(0,(TreeNode)null,ds); } // 递归添加树的节点
    public void AddTree(int ParentID,TreeNode pNode,DataSet ds) 
    {
    TreeNode Node;
    DataView dvTree = new DataView(ds.Tables[0]);
    //过滤ParentID,得到当前的所有子节点
    dvTree.RowFilter =  "[ParentID] = " + ParentID;
    foreach(DataRowView Row in dvTree) 
    {
    if(pNode == null) 
    {    //添加根节点
    Node = new TreeNode();
    Node.Text = Row["ModuleName"].ToString();
    Node.Tag = Row["ModuleID"].ToString();
    tv_Flag.Nodes.Add(Node);
    AddTree(Int32.Parse(Row["ModuleID"].ToString()),Node,ds);    //再次递归

    else 
    {   //添加当前节点的子节点
    Node = new TreeNode();
    Node.Text = Row["ModuleName"].ToString();
    Node.Tag = Row["ModuleID"].ToString();
    pNode.Nodes.Add(Node); }
    }
    }
    #endregion
      

  3.   

    private void SetNodeCheckStatus( TreeNode tn, bool Checked )
    {
    if( tn == null ) return; // Check children nodes
    foreach (TreeNode tnChild in tn.Nodes)
    {
    tnChild.Checked = Checked;
    SetNodeCheckStatus( tnChild, Checked );
    } // Set parent check status
    TreeNode tnParent = tn;
    int nNodeCount = 0;
    while( tnParent.Parent != null )
    {
    tnParent = (TreeNode)(tnParent.Parent);
    nNodeCount = 0;
    foreach( TreeNode tnTemp in tnParent.Nodes )
    {
    if( tnTemp.Checked == Checked )
    {
    nNodeCount++;
    }
    }
    if(nNodeCount == tnParent.Nodes.Count)
    {
    tnParent.Checked = Checked;
    }
    else
    {
    tnParent.Checked = false;
    }
    } }
    private void tv_Flag_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e)
    {
    if( e.Action != TreeViewAction.Unknown )
    {
    //Event call by mouse or key-press
    SetNodeCheckStatus( e.Node, e.Node.Checked );
    }
    }
      

  4.   

    http://www.microsoft.com/china/community/Column/30.mspx
      

  5.   

    this.tv.Nodes.Clear();
    System.Windows.Forms.TreeNode root=new TreeNode(“节点名称”,4,4);
    root.Tag=“节点名称”;
    this.tv.Nodes.Add(root);
    foreach(DataRow dr in DataEntity.downDataObj.sqlDs.Tables["department"].Rows)
    {
    System.Windows.Forms.TreeNode node=new TreeNode(dr["字段名称"].ToString(),4,5);
    node.Tag=dr["字段名"].ToString();
    this.tv.Nodes[0].Nodes.Add(node);
    }
    this.tv.ExpandAll();