So I was reading a tutorial (here) that said that you should bind the treeview to some data, instead of just adding the nodes to the tree manually:
TNode item = new TNode("1");
item.Header = "node1";
item.FontWeight = FontWeights.Normal;
tv_master.Items.Add(item);
TNode item2 = new TNode("2");
item2.Header = "node2";
item2.FontWeight = FontWeights.Normal;
item.Items.Add(item2);
So is this right? or does it really not matter at all?
If I should be binding the treeview data, could you point me in the direction of a VERY simple tutorial? I have nev开发者_StackOverflow社区er done anything like this (databinding etc), and found it really tough to follow the above tutorial.
thanks!
What you have found is a very good tutorial and thats exactly how it should be done. Here is a simpler one.
So is this right? or does it really not matter at all?
No, in WPF world its a crime. DataBinding
is one of the core features of WPF and I strongly recommend you to read about it. Always databind do not manually loop and add grid rows or tree nodes, let the framework do it for you.
精彩评论