I have a WinTree which I want to totally populate via DataBinding. The root nodes are of one type and children nodes are of a totally different type. On the root node, the code calls:
treeNode.Nodes.SetDataBinding(childDataSource, string.empty);
And the children are displayed showing the first property of the object in which the given node is bound.
There should be two columns from the childDataSource displayed. How does one go about setting up a column set for the children such that dataBinding knows which columns in the dataset to bind to?
When I try putting in a property name, which happens to be a property of a derived class, there are no children:
class base { public string name { get; set; } }
class derived : base { string details { get; set; } }
class CustomDataSet : BindingList<derived> {}
I want to show both the name and details under the root. The root is of a different type not shows in this code
Sam
Hi Sam,
To set up a hierarchy, you should set up the hierarchy in your data source, rather than trying to bind the root nodes of the tree and then also bind the child nodes.
It looks like you are using a derived BindingList class. That's fine and will give you a single level of data. To get child data, the objects in the BindingList (in the example above, the derived object) must expose a public property that returns another BindingList which contains the child rows.
If you bind the tree to a BindingList whose items expose a BindingList property of their own, the tree will display the hierarchy for you automatically.
Normal 0 false false false MicrosoftInternetExplorer4
Ok, so the inheritance is not an issue, didn't think so.
I do agree 100% that setting up the binding in the data source is the quickest and easiest, but in my current situation this is not the case. It is my impression that since there is a method SetDataBinding() on treeNode.Nodes, that setting a data set on a node was something the control is able to do. Am I mistaken?
If I am not, what I am wondering is: How do I control which columns are displayed when using treeNode.Nodes. SetDataBinding()? Is this ONLY done via the data set?