This is a migrated thread and some comments may be shown as answers.

Bind TreeView with Dataset that contains a DataRelation

6 Answers 320 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 2
Mike asked on 07 Aug 2008, 04:36 PM

Hi Guys,

I am having a problem populating a RadTreeView with a Dataset that contains a DataRelation. As I step through the code the DataSet returns two tables and they both contain the correct values I want shown on the form, however, it only displays the first table’s data on my form. I am using the most current version of controls.

The following is a snippet of the source code that contains the problem described above:

 private void LoadTreeView()  
        {  
            DataSet dsData = new DataSet();  
            int intDocID = 10;  
 
            tvrDocs.Nodes.Clear();  
 
            dsData = AppDocument.GetDocumentTreeView(intDocID);  
 
            if (dsData != null)  
            {  
                DataColumn parentColumn = dsData.Tables[0].Columns["DocGlobalRuleTypeID"];  
                DataColumn childColumn = dsData.Tables[1].Columns["DocGlobalRuleTypeID"];  
 
                // Create DataRelation.  
                DataRelation drGlobalVar;  
                drGlobalVar = new DataRelation("GlobalVar", parentColumn, childColumn);  
                // Add the relation to the DataSet.  
                dsData.Relations.Add(drGlobalVar);  
 
                tvrDocs.DataSource = dsData;  
            }  
            dsData.Dispose();  
 
        } 

Please let me know what I can do to solve this issue.

Many Thanks,

Mike

6 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 08 Aug 2008, 12:26 PM
Hello Mike,

In you code snippet I noticed that only the DataSource property is set to the RadTreeView control.
This will work fine if you want to show a list in RadTreeView. In order to show hierarchical data you have to tell RadTreeView how to bind to that data, by describing the relations between the different tables/collections in your data source using RelationBinding objects. For more information you can take a look at this article in the online documentation.

Kind regards,
Jordan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 2
answered on 08 Aug 2008, 01:24 PM
Hi Guys,

Thanks for the quick responce. I have reviewed the example and i was wondering if there was a way to implement this through code and not by using a wizard?

Thanks again,

Mike
0
Jordan
Telerik team
answered on 08 Aug 2008, 02:58 PM
Hello mike scardina,

The wizard that is shown in the help article just generates a strongly typed DataSet. If you do not want to use an auto generated DataSet (may be you have custom business objects or classes generated by an ORM tool) then you can bind RadTreeView to custom business objects as well.

In order to give you a more concrete answer I will need to know what exactly you want to implement through code.

 
Greetings,
Jordan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Geert
Top achievements
Rank 1
answered on 29 Apr 2009, 11:22 AM
I have the same question

I have a dataset (dsTree) with 2 datatables

Datatable 1 fields:

Platform
Name

Datatable 2 fields:

Platform
Fieldname
Assigned

I have created a relation with the following code:
dsTree.Relations.Add(dsTree.Tables[0].Columns["Platform"],dsTree.Tables[1].Columns["Platform"]); 

My purpose is to show this in the tree a node "Platform" and then indented all the fields of that platform.
How does it work?
0
Victor
Telerik team
answered on 30 Apr 2009, 01:09 PM
Hello Geert,

Thank you for writing. Have you seen this knowledge base article? Your DataSet needs to have relations and you need to add those relations to the tree view (the article shows how to do this).

Please write back if you have other questions.

Sincerely yours,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Stefan
Telerik team
answered on 22 Mar 2011, 02:45 PM
Hello guys,

Please note that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out. For more information on our latest release refer to this blog post.

All the best,
Stefan
the Telerik team
Tags
Treeview
Asked by
Mike
Top achievements
Rank 2
Answers by
Jordan
Telerik team
Mike
Top achievements
Rank 2
Geert
Top achievements
Rank 1
Victor
Telerik team
Stefan
Telerik team
Share this question
or