数据库结构 ID int(4) 主键 ParentID int(4) ConText nvchar(50) 均No Null
***********************************************************************
函数说明
public void AddTree(int ParentID, TreeNode pNode,TreeView treeView,DataTable dt)
其中treeView为TreeView控件,dt为数据集中的表。
调用示例:
dt = (DataTable)td.RetiereTree();
AddTree(0, (TreeNode)null,treeView1,dt);
Vs2005 C# WindowsXp 测试通过。
***********************************************************************
public void AddTree(int ParentID, TreeNode pNode,TreeView treeView,DataTable dt)
{
DataView dvTree = new DataView(dt);
//过滤ParentID,得到当前的所有子节点
//dvTree.RowFilter = "[PARENTID] = " + ParentID;
dvTree.RowFilter = "[PARENTID]=" + ParentID;
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
foreach (DataRowView Row in dvTree)
{
TreeNode Node = new TreeNode();
if (pNode == null)
{ //添加根节点
Node.Text = Row["ConText"].ToString();
treeView.Nodes.Add(Node);
//Node.Expanded = true;
AddTree(Int32.Parse(Row["ID"].ToString()), Node,treeView,dt); //再次递归
}
else
{ //̀添加当前节点的子节点
Node.Text = Row["ConText"].ToString();
pNode.Nodes.Add(Node);
//Node.Expanded = true;
AddTree(Int32.Parse(Row["ID"].ToString()), Node,treeView,dt); //再次递归
}
}
}
***********************************************************************
函数说明
public void AddTree(int ParentID, TreeNode pNode,TreeView treeView,DataTable dt)
其中treeView为TreeView控件,dt为数据集中的表。
调用示例:
dt = (DataTable)td.RetiereTree();
AddTree(0, (TreeNode)null,treeView1,dt);
Vs2005 C# WindowsXp 测试通过。
***********************************************************************
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://cshapwinforms.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)