Bind TreeView with Dataset that contains a DataRelation

7 posts, 0 answers
  1. Mike
    Mike avatar
    76 posts
    Member since:
    Nov 2004

    Posted 07 Aug 2008 Link to this post

    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

  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 08 Aug 2008 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mike
    Mike avatar
    76 posts
    Member since:
    Nov 2004

    Posted 08 Aug 2008 Link to this post

    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
  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 08 Aug 2008 Link to this post

    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.
  6. Geert
    Geert avatar
    14 posts
    Member since:
    Feb 2009

    Posted 29 Apr 2009 Link to this post

    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?
  7. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 30 Apr 2009 Link to this post

    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.
  8. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 22 Mar 2011 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready