private void BindTreeView() 2 { 3 treeView1.Nodes.AddRange(GetChildNodes(dt, 0)); 4 } 5 6 private TreeNode[] GetChildNodes(DataTable dt, int pId) 7 { 8 var nodes = new List<TreeNode>(); 9 var rows = dt.AsEnumerable().Where(s => Convert.ToInt32(s["pId"]) == pId); 10 foreach(var row in rows) 11 { 12 var node = new TreeNode(); 13 node.Text = row["Name"].ToString(); 14 node.Tag = row["Tag"].ToString(); 15 node.Nodes.AddRange(GetChildNodes(dt, Convert.ToInt32(row["Tag"]))); 16 nodes.Add(node); 17 } 18 return nodes.ToArray(); 19 }