How to binding TreeView to Unlimit Category?
-
I have a class like this: <pre> public class EmpCtg { public int ID { get; set; } public string Name { get; set; } public EmpCtg Parent { get; set; } } </pre> Collection of this class: <pre> List<EmpCtg> ListEmpCtg = //....get list<empctg> </empctg></pre> I want binding ListEmpCtg to TreeView, and show look like this: <pre> EmpolyeeCategory | ---------Ctg1 | | ---------Ctg2 | | | | | --------Ctg3 | | | | | --------Ctg4 | | | | | --------Ctg5 . . . </pre> I know that I can write in the code by hand, but I would like to know whether to use DataTemplate? What should I do? Thanks!
-
I have a class like this: <pre> public class EmpCtg { public int ID { get; set; } public string Name { get; set; } public EmpCtg Parent { get; set; } } </pre> Collection of this class: <pre> List<EmpCtg> ListEmpCtg = //....get list<empctg> </empctg></pre> I want binding ListEmpCtg to TreeView, and show look like this: <pre> EmpolyeeCategory | ---------Ctg1 | | ---------Ctg2 | | | | | --------Ctg3 | | | | | --------Ctg4 | | | | | --------Ctg5 . . . </pre> I know that I can write in the code by hand, but I would like to know whether to use DataTemplate? What should I do? Thanks!
I use TreeView extensively. It is a rather "unique" control with a lot of pitfalls. I strongly suggest you expend the effort and write custom code around your TreeView controls. Otherwise, if you really want to just use binding, refer to this article on CodeProject: Data Binding TreeView in C#[^]