public void AddNode(MatchTypeList matchTypeList)
{
//添加父节点
if (!treeView1.Nodes.ContainsKey(matchTypeList.ParentId))//先判断是否已经存在这个节点
{
TreeNode root = new TreeNode();//创建节点
root.Name = matchTypeList.ParentId;
root.Text = matchTypeList.ParentName;
treeView1.Nodes.Add(root);//将节点添加到treeView1上
}
//添加子节点
var root1=treeView1.Nodes.Find(matchTypeList.ParentId, false).FirstOrDefault();//先判断是否已经存在这个根节点
if (!root1.Nodes.ContainsKey(matchTypeList.MatchTypeId))
{
TreeNode node = new TreeNode();//创建节点
node.Name = matchTypeList.MatchTypeId;
node.Text = matchTypeList.MatchTypeName;
root1.Nodes.Add(node);//将子节点添加到根节点上
}
}