Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2387
Advanced DataBinding w/ columns
posted

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

Parents
  • 469350
    Suggested Answer
    Offline posted

    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.

Reply Children