#region treetView加载 private void treeViewLoad() { DataView dv = navds.tbSiteKind.AsDataView(); treeView1.Nodes.Clear(); //foreach (DataRowView row in dv) //{ // TreeNode tn = new TreeNode(); // tn.Text = row[0].ToString(); // treeView1.Nodes.Add(tn); // addChildNode(tn); //} } private void addChildNode(TreeNode tn) { DataView dvc = navds.site.AsDataView(); string filt = "siteKind like '%" + tn.Text.ToString()+"'"; dvc.RowFilter = filt; //参考: //http://tech.it168.com/KnowledgeBase/Articles/0/5/8/058be1cc2a1e95f0dd1e7f9ac71f9d70.htm //http://blog.csdn.net/luols/article/details/5539573 DataTable dt1 = dvc.ToTable(true, "site"); foreach (DataRow datav in dt1.Rows) { TreeNode node = new TreeNode(); node.Text = datav["site"].ToString(); //node.Tag=datav["rowid"].ToString(); tn.Nodes.Add(node); addMimNode(node); } } private void addMimNode(TreeNode node) { DataView dv2 = navds.site.AsDataView(); string filt2 = "site like '%" + node.Text.ToString() + "'"; dv2.RowFilter = filt2; foreach (DataRowView dvr in dv2) { TreeNode nd = new TreeNode(); nd.Text = dvr["cannle"].ToString(); nd.Tag = dvr["siteurl"].ToString(); node.Nodes.Add(nd); } } #endregion
插入三层的treeview代码。