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
8 Answers, 1 is accepted

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); |
} |
} |
} |
} |
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; |
} |
} |
} |
I hope this helps.
Regards,
Jordan
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

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!

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.
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

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?
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.
Julian Benkov
the Telerik team
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.
Stefan
the Telerik team