[原创]动态的给TREEVIEW加载节点
数据表的设置:
CREATE TABLE NODETABLE
(
Node int NOT NULL IDENTITY (1, 1),
ParentNode int NOT NULL,
NodeDesc nvarchar(50) NOT NULL
)
把NODETABLE数据加载到DataTable
public void getTreeView(int parentnode,TreeNodeCollection node)
{
DataTable dt = new DataTable();
//此行插入把加载的DataTable数据赋给dt;
dv = dt.DefaultView;
dv.RowFilter = "ParentNode = "+parentnode;
try
{
foreach(DataRowView drv in dv)
{
TreeNode tNode = node.Add(drv["NodeDesc"].ToString());
getTreeView((int)drv["Node"],tNode.Nodes,ppo);
}
}
finally
{
dt.Dispose();
}
}
CREATE TABLE NODETABLE
(
Node int NOT NULL IDENTITY (1, 1),
ParentNode int NOT NULL,
NodeDesc nvarchar(50) NOT NULL
)
把NODETABLE数据加载到DataTable
public void getTreeView(int parentnode,TreeNodeCollection node)
{
DataTable dt = new DataTable();
//此行插入把加载的DataTable数据赋给dt;
dv = dt.DefaultView;
dv.RowFilter = "ParentNode = "+parentnode;
try
{
foreach(DataRowView drv in dv)
{
TreeNode tNode = node.Add(drv["NodeDesc"].ToString());
getTreeView((int)drv["Node"],tNode.Nodes,ppo);
}
}
finally
{
dt.Dispose();
}
}