【C#源碼】treeview 控制項應用執行個體

來源:互聯網
上載者:User

 

private TreeView BuildTree(TreeView tree,DataTable tb,string KeyField,string ParentKeyField,string NameField,long TopWithValue)
  ...{
   this.tvwDept.Nodes.Clear();
   // 添加全部科室節點
   TreeNode node=new TreeNode("全部科室",2,0);
   node.Tag=null;
   //AddNodes(node,tb,KeyField,ParentKeyField,NameField);
   tree.Nodes.Add(node);

   for(int i=0;i<=tb.Rows.Count-1;i++)
   ...{
    if(Convert.ToInt64(tb.Rows[i][ParentKeyField])==TopWithValue)
    ...{
     node=new TreeNode(tb.Rows[i][NameField].ToString().Trim());
     node.Tag=tb.Rows[i][KeyField].ToString();
     AddNodes(node,tb,KeyField,ParentKeyField,NameField);
     tree.Nodes.Add(node);
    }
   }
   return tree;
  }

private void AddNodes(TreeNode parNode,DataTable tb,string KeyField,string ParentKeyField,string NameField)
  ...{
   DataTable tbChild=tb.Clone();
   DataRow[] rows=tb.Select(ParentKeyField+"="+parNode.Tag.ToString());
   if(rows.Length!=0) 
    parNode.ImageIndex=1;
   else
    parNode.ImageIndex=2;
   for(int i=0;i<=rows.Length-1;i++)
   ...{
    tbChild.Rows.Add(rows[i].ItemArray);
   }
   for(int i=0;i<=tbChild.Rows.Count-1;i++)
   ...{
    TreeNode node=new TreeNode(tbChild.Rows[i][NameField].ToString().Trim());
    node.Tag=tbChild.Rows[i][KeyField].ToString();
    parNode.Nodes.Add(node);
    AddNodes(node,tb,KeyField,ParentKeyField,NameField);
   }
  } 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.