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?
Hi,
Yes, you are correct. You can bind an individual nodes collection, such as a collection of child nodes.
The ColumnSet for those nodes should be automatically generated, assuming you left the AutoGenerateColumnSets property to the default, which is true.
If the generated ColumnSet is wrong, there could be a number of reasons why.
The ColumnSets are matched up to the data source by name. So it's possible that if you are binding the root-level nodes of the tree that maybe there is a ColumnSet that already exists with the same name as the one you are binding the child nodes to.
Are you binding the root nodes of the tree?
What kind of data source are you using? If it's a DataSet or DataTable, then make sure you set the TableName on it to something unique.
Another option is that the ColumnSet somehow got generated at design-time with only one column because you bound the tree at design-time to the same data source before it had both columns in it. If that's the case, then you may have to reset the ColumnSets collection at design-time in order to get rid of the incorrect ColumnSet.
If none of the helps, I recommend that you trap the ColumnSetGenerated event and examine the ColumnSets that are getting created and that might provide some clue about what's going wrong.
If you want to manually create your ColumnSets, you could do that, also. You just have to either make sure the Key of the ColumnSet matches the name used by the band in the data source. Or else assign the ColumnSet explicitly via the Override.
13 years after the original post this forum reply helped me figure out my issue. Thanks!