Hierarchical Binding with lists

9 posts, 0 answers
  1. helloS
    helloS avatar
    4 posts
    Member since:
    Feb 2008

    Posted 26 Jan 2009 Link to this post

    Hello

    I am attempting to bind 3 tables of data to a Treeview using lists:

     

     

     

     

     
                vwMarketTypex mtype = markettypecontroller.GetView(STR_MarketType, STR_TimePeriod);  
                List<Symbol> currencies = Symbolcontroller.GetSymbolsByMarketType(mtype.MarketTypeID);  
     
                List<Scenario> scenarios = senariocontroller.GetAllScenarios();  
                List<RZEROMarketData.Data.RuleSet> rulesetsx = rscontroller.GetAllRulesets();  
     
                radTreeView1.RootRelationDisplayName = "Curreny Pair";  
                
                var newRelationBinding = new RelationBinding("Scenarios", scenarios, null"ScenarioDescription""ScenarioId");  
         
                radTreeView1.RelationBindings.Add(newRelationBinding);  
          
                var newRelationBinding1 = new RelationBinding("Rulesets", rulesetsx, null"Name""RulesetId");  
                radTreeView1.RelationBindings.Add(newRelationBinding1);  
             
     
                radTreeView1.DataSource = currencies; 



    The last object rulesetsx does not bind ..please can you advise if I am on the right track.

    Thanks

     

     

     

     

     

  2. helloS
    helloS avatar
    4 posts
    Member since:
    Feb 2008

    Posted 26 Jan 2009 Link to this post

     

     

     Hello
    Resorted to binding the treeviewvia it's nodes
    That way I have a handle on exactly what is happening


    private void LoadTreeView()  
            {  
                vwMarketTypex mtype = markettypecontroller.GetView(STR_MarketType, STR_TimePeriod);  
                List<Symbol> currencies = Symbolcontroller.GetSymbolsByMarketType(mtype.MarketTypeID);  
     
     
     
                foreach (Symbol symbol in currencies)  
                {  
                    var currnode = new RadTreeNode(symbol.Symbol1);  
                    currnode.Tag = symbol.SymbolId;  
                    currnode.ContextMenu = radContextMenu1;  
                    radTreeView1.Nodes.Add(currnode);  
                    List<Scenario> scenarios = senariocontroller.GetByCurrencyID(symbol.SymbolId);  
                    foreach (Scenario scenario in scenarios)  
                    {  
                        var scenarionode = new RadTreeNode(scenario.ScenarioDescription);  
                        scenarioscenarionode.Tag = scenario.ScenarioId;  
                        scenarionode.ContextMenu = radContextMenu1;  
                        currnode.Nodes.Add(scenarionode);  
     
                        List<RZEROMarketData.Data.RuleSet> rulesetsx =  
                            rscontroller.GetRulesetsByScenario(scenario.ScenarioId);  
                        foreach (RZEROMarketData.Data.RuleSet ruleSet in rulesetsx)  
                        {  
                            var rulesetonode = new RadTreeNode(ruleSet.Name);  
                            rulesetonode.Tag = ruleSet.RulesetId;  
                            rulesetonode.ContextMenu = radContextMenu1;  
                            scenarionode.Nodes.Add(rulesetonode);  
                        }  
                    }  
                }  
            } 

     

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 30 Jan 2009 Link to this post

    Hi helloS,

    I am glad to see that you have found a solution. Indeed if you need more control over the process of binding the RadTreeView to the data you have to implement that with custom logic (as you did).

    Now, if you intend to use the data binding functionality of RadTreeView you should note that there is a difference when binding to a DataSet or to business objects. That difference comes from the presence of relations between the data table in a data set. When working with business objects, these relations are in most cases implemented with collection properties like in the example bellow.

    So in order to bind RadTreeView to a list of business objects you could write the following code:
    BindingList<Artist> artists = SampleRelatedData.GetArtistObjects(DataBindingTests.musicCollectionDataSet.Artists); 
     
    RelationBinding albumsBinding = new RelationBinding("Albums", artists, "Albums"); 
    albumsBinding.DisplayName = "Albums"
    albumsBinding.ValueMember = "ID"
    this.radTreeView1.RelationBindings.Add(albumsBinding); 
    this.radTreeView1.RelationBindings.Add(new RelationBinding("Songs", artists, "Albums.Songs")); 
     
    this.radTreeView1.RootRelationDisplayName = "Artists"
    this.radTreeView1.ValueMember = "ID"
    this.radTreeView1.DataSource = artists; 


    And here is the Artist class with the Albums collection property:
    public class Artist : DataObject 
        { 
            public Artist() 
            { 
            } 
     
            public Artist(string name) 
            { 
                this.name = name; 
            } 
     
            private string name; 
     
            public string Name 
            { 
                get 
                { 
                    return this.name; 
                } 
                set 
                { 
                    this.name = value; 
                } 
            } 
     
            private object id; 
     
            public object ID 
            { 
                get 
                { 
                    return this.id; 
                } 
                set 
                { 
                    this.id = value; 
                } 
            } 
     
            private BindingList<Album> albums = new BindingList<Album>(); 
     
            public BindingList<Album> Albums 
            { 
                get 
                { 
                    return this.albums; 
                } 
            } 
     
            public override IList List 
            { 
                get 
                { 
                    return this.albums; 
                } 
            } 
        } 
    The Album and Song classes can be easily implemented in a similar manner.
    I hope this helps.

    Regards,
    Jordan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Buggagos
    Buggagos avatar
    2 posts
    Member since:
    Jul 2010

    Posted 14 Jul 2010 Link to this post

    Dear all,

    i am new to Telerik and i am pulling hair (whatever is left) trying to figure out how to use the relations so as to have a 4 level deep hierarchy rendered on a treeview control.

    Although what HelloS did makes sense, i think the whole point (or at least a good one) of using (and buying Telerik.Rad*) is to exactly avoid manually iterating the collections and iteratively build the treeview.

    I have seen the examples and unfortunately they only do the easy job of showing how to render a 2 level deep relationship.

    I would much appreciate any feedback on this and I think many others would benefit from a clear solution.

    Here is a sample scenario to work on.

    The world has countries. Each country has cities. Each city has municipalities. Each municipality has citizens.

    Programmatically to get all the citizens of a country you would have to do:

    myworld.countries("UK").cities("London").municipalities("central london").citizens

    Rendering all 4 levels to a treeview based on the manual process of HelloS is easy. How about doing it the "relations" way (using objects)?

    Many thanks!



  6. Buggagos
    Buggagos avatar
    2 posts
    Member since:
    Jul 2010

    Posted 14 Jul 2010 Link to this post

    Damn, i think i got it worked out...It seems that even by describing one's problem helps !....

    For anyone interested here is the solution based on the sample senario above:

    Imports Telerik.WinControls
     
    With myWorldDisplayForm
       .RadTreeView1.RootRelationDisplayName = "Earth"
       Dim newBinding As UI.RelationBinding
       newBinding = New UI.RelationBinding("Cities", myworld, "Countries.Cities", "CityName", "CityName")
       .RadTreeView1.RelationBindings.Add(newBinding)
       newBinding = New UI.RelationBinding("Municipalities", myworld, "Countries.Cities.Municipalities", "MunName", "MunName")
       .RadTreeView1.RelationBindings.Add(newBinding)
       newBinding = New UI.RelationBinding("Citizens", myworld, "Countries.Cities.Municipalities.Citizens", "PersonName", "PersonName")
       .RadTreeView1.RelationBindings.Add(newBinding)
       .RadTreeView1.DataSource = myworld.Countries
    End With

    Each of the corresponding classes has got some properties (anything you like) and a List of the children objects....For example the country object has got a List(Of Cities).

    Hope this one clarifies a few things for new users of the controls like me....

    Many thanks.
  7. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 20 Jul 2010 Link to this post

    Hello Buggagos,

    Thank you for sharing your code. You can also take a look at the help article that describes how to use the RelationBinding objects. Please write again if you need further assistance with our controls.

    Sincerely yours,
    Victor
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. John
    John avatar
    10 posts
    Member since:
    Feb 2011

    Posted 12 Feb 2011 Link to this post

    I am attempting the hierarchial binding with lists and am getting an error that says "Child list for field _branches cannot be created."  My code is as follows..


    RelationBinding branchesBinding = new RelationBinding("Branches", _branches);
                    branchesBinding.DisplayName = "Name";
                    branchesBinding.ValueMember = "OfficeBranchID";
                    radTreeView.RelationBindings.Add(branchesBinding);
      
                    radTreeView.RelationBindings.Add(new RelationBinding("Levels", _branches, "_branches.Levels"));
                    radTreeView.RelationBindings.Add(new RelationBinding("Offices", _branches, "_branches.Levels.Offices"));
                    radTreeView.RelationBindings.Add(new RelationBinding("Districts", _branches, "_branches.Levels.Offices.Districts"));
                    radTreeView.RelationBindings.Add(new RelationBinding("Candidates", _branches, "_branches.Levels.Offices.Districts.Candidates"));
      
                    radTreeView.RootRelationDisplayName = "Branches";
                    radTreeView.ValueMember = "OfficeBranchID";
                    radTreeView.DataSource = _branches;

    My object is a List<BranchDO> _branches and each BranchDO contains a List<LevelDO> Levels and each LevelDO contains a List<OfficeDO> Offices and each OfficeDO contains a List<DistrictDO> Districts.  The child lists could contain data or could be null (or an empty list if that works better).  What am i missing?
  9. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 17 Feb 2011 Link to this post

    Hi john,

    This functionality is not supported by the current version of RadTreeView. You can use RelationBinding only with DataSet / DataTable types of data with defined relation between tables. More information you can find in our online documentation. For your scenario you can try the Load-On-Demand feature of RadTreeView. 

    I hope this was helpful.

    Best wishes,
    Julian Benkov
    the Telerik team
  10. Stefan
    Admin
    Stefan avatar
    2890 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.

    Greetings,
    Stefan
    the Telerik team
Back to Top
UI for WinForms is Visual Studio 2017 Ready