Search code examples
c#winformsdevexpressdatasourcextratreelist

binding data to the treelist control


I'm having one table which contains the field as "IsBulitIn" & which is of bit type. Depending on the field value i filtered my table & i got to set of data . I used dataview for each type of data. Now i'm having two dataview's . I want to create two parent nodes at run time . The name may be "BuiltIn Group" & "My Group". & i want to set these two dataviews to the my above two parent node.

Is it possible by to set the datasource property to the each parent node?

thanks.


Solution

  • Generally, there is a way to do this, though this way is not a straight forward. First, I should tell, that the TreeListNode class does not provide the DataSource property. So, it is impossible to just set a property and achieve the required effect. Anyway, I would suggest that you create child nodes for these nodes yourself:

    void PopulateNodes(TreeListNode parentNode, DataView dataView) { 
                treeList1.BeginUnboundLoad();
                try {
                    for(int i = 0; i < dataView.Count; i++) {
                        treeList1.AppendNode(new object[] { dataView[i]["SomeFieldName"] }, parentNode);
                    }
                }
                finally {
                    treeList1.EndUnboundLoad();
                }
            }
    

    To add a parent node programmatically, use the following code:

        TreeListNode parentNode = treeList1.AppendNode(new object[] { "parent" }, null);