Winform递归绑定树节点

/// 
/// 绑定树节点
/// 
/// 
/// 
public void Band_TreeView(int pid,TreeNode treeNode)
{
string json = tree_helper.Get("Get?pid="+pid);
List list = JsonConvert.DeserializeObject>(json);
foreach (TreeViewModel item in list)
{
//实例化一个新的treenode
TreeNode tn = new TreeNode();
tn.Text = item.Tname;
tn.Tag = item.Id;  //控件的额外属性
//向总节点添加此节点
treeNode.Nodes.Add(tn);
//递归调用自身继续绑定
Band_TreeView(item.Id,tn);
}
}

你可能感兴趣的:(Winform递归绑定树节点)