private void InitMyTreeView(TreeNodeCollection Nds, string PID, ref DataTable dt)
{ DataView dv = new DataView(); TreeNode tmpNd; string strId; dv.Table = dt; dv.RowFilter = "mainId ='" + PID + "'"; dv.Sort = "ID"; foreach (DataRowView drv in dv)
{ tmpNd = new TreeNode(); tmpNd.Text = drv["Title"].ToString();
tmpNd.Value = drv["ID"].ToString().Trim(); tmpNd.ToolTip = drv["Title"].ToString().Trim(); tmpNd.ImageToolTip = drv["Title"].ToString().Trim(); tmpNd.Target = "你目標框架的名稱"; Nds.Add(tmpNd); strId = drv["ID"].ToString();
InitMyTreeView(tmpNd.ChildNodes, strId, ref dt); } } 調(diào)用時用:初始化 DataTable Dt=(你需要查詢的那個整表);
然后調(diào)用:InitMyTreeView(this.TreeView1.Nodes,"0",ref Dt);
就可以了 上面代碼只需要把漢字部分用自己的數(shù)據(jù)結構和字符串替換掉就可以了,測試通過的 呵呵 |
|