1 下载 treeGridView.DLL库文件。
2 添加到工程中。
右键“工具箱”选择“选择项” 弹出对话框
选择“浏览” 选中下载还的dll库文件。完成后工具箱中会有 treeGridView控件,如下图
拖动控件到windform 中
添加代码
List<personcl> lst = new List<personcl>();
//personcl per = new personcl { name = "cese", age = 1 };
personcl per1 = new personcl { name = "cese", age = 2 };
//lst.Add(per);
lst.Add(per1);
personcl per2 = new personcl { name = "cese", age = 3 };
per1.subitem.Add(per2);
personcl per3 = new personcl { name = "cese", age = 4 };
per2.subitem.Add(per3);
//lst.Add(new personcl { name = "wyl", age = 10, subitem = new List<personcl> { new personcl { name = "wyl", age = 11 } } });
SetNodes(lst, treeGridView1.Nodes);
public class personcl
{
public string name = "1";
public int age = 10;
public List<personcl> subitem = new List<personcl>();
}
private void SetNodes(IEnumerable<personcl> lst, TreeGridNodeCollection nodes)
{
foreach (var item in lst)
{
var node = nodes.Add(item.name, item.age);
node.ImageIndex = 0;
SetNodes(item.subitem, node.Nodes);
}
}
参考: https://www.cnblogs.com/mrtiny/p/5174095.html