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

Using two datatypes on a RadTreeListView

8 Answers 336 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 01 Sep 2010, 05:23 PM
Hi,

I'm currently trying to display two datatypes in a single RadTreeListView. The first datatype, 'Desk', have only two properties: 'Name', and a property 'Books' containing the second datatype: 'Book'.

public class Desk
{
    public string Name { get; set; }
    public List<Book> Books { get; set; }
}
 
public class Book
{
    public string Name { get; set; }
    public string Location { get; set; }
    // Other stuff
}

I want to display a column 'Name' populated by both types, and a few other columns (in this example : 'Location') populated only for the child elements (Book).

Even though I wasn't able to create different templates for each types, the data could be binded since the property names are matching, and I can edit the Desk's properties. But the grid throws a 'Object does not match target type' exception when I try to edit a Book's properties.

<telerikGridView:RadTreeListView x:Name="RadTreeListView1"
                    AutoGenerateColumns="False"
                    IsReadOnly="False"
                    RowIndicatorVisibility="Collapsed"                                
                    ItemsSource="{Binding Path=Desks}">
    <telerikGridView:RadTreeListView.ChildTableDefinitions>
        <telerikGridView:TreeListViewTableDefinition ItemsSource="{Binding Path=Books}" />
    </telerikGridView:RadTreeListView.ChildTableDefinitions>
    <telerikGridView:RadTreeListView.Columns>                      
        <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Path=Name}" Header="Name" Width="150"/>
        <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Path=Description}" Header="Description" Width="*"/>
        <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Path=Location.Name}" Header="Location" Width="100"/>
        <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Path=Intention}" Header="Intention" Width="100"/>
        <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Path=TreatmentType}" Header="Treatment Type" Width="100"/>
        <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Path=AccountingTreatment}" Header="Accounting Treatment" Width="100"/>
        <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Path=IfrsType}" Header="Ifrs Type" Width="100"/>                       
    </telerikGridView:RadTreeListView.Columns>
</telerikGridView:RadTreeListView>

Am I doing something wrong? Is there a workaround for this problem?

(enclosed screenshot)

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 02 Sep 2010, 07:21 AM
Hello,

 Heterogeneous data are not supported in RadTreeListView. To achieve your goal you can use RadGridView hierarchy or RadTreeView. 

Best wishes,
Vlad
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
0
Kevin
Top achievements
Rank 1
answered on 02 Sep 2010, 08:18 AM
Well, RadGridView is really ugly when handling hierarchical data, and RadTreeView has, as far as I know, no easy way to display multiple columns. I'll find another way, but RadTreeListView would have been the perfect compromise. You should give it some thought!

 - Allow to set different bindings in XAML for each type of object: for objects of type Type1, bind this property to column 1 and this property to column 2, for objects of type Type2 bind this property to column 1 and this property to column 2, and so on.
 - Use the type of the current row rather than the first row when accessing properties through reflection.

Looking forward to seeing a RadTreeListView handling multiple object types in future Telerik versions :)
0
Vlad
Telerik team
answered on 02 Sep 2010, 08:28 AM
Hello,

 The treelistview will unable to display heterogeneous data since every type will have different properties and in this case you will get different columns - you cannot align different columns.

Greetings,
Vlad
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
0
Kevin
Top achievements
Rank 1
answered on 02 Sep 2010, 08:35 AM
Sure, but you can use a template system to bind a property to a column index rather than an actual column.

In the XAML, define two columns, called "Name" and "Description".

Then define one template for each datatype, and decide what property would be binded in the "Name" column, and what property would be binded in the "Description" column. So can bind the property "Name" of the type "Type1" to the "Name" column, and the property "Label" of the type "Type2" to this same column.

In my case I will be forced to use facade objects to get this behavior. It's not a massive amount of work, but it's still additional time spent. 
0
Tgaud
Top achievements
Rank 1
answered on 15 Sep 2010, 09:58 AM
Well it should be possible to achieve this.
If I remember well, another UI component dev team begining by "In" and finishing by "ics" allow this behavior in his components.

So it should be great to have telerik to support it too..
0
Vlad
Telerik team
answered on 15 Sep 2010, 10:04 AM
Hello,

 You can use template selectors however features like sorting, filtering, etc. will not work.

Best wishes,
Vlad
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
0
Michał
Top achievements
Rank 1
answered on 20 May 2013, 05:20 PM
Hello,

does newest version of RadTreeListView still not support heterogeneous data?
I'm interested to display them in one RadTreeListView control and allow user to filter the content by property which is available on each of type which is in ItemsSource collection.

Regards,
Michal.
0
Nick
Telerik team
answered on 23 May 2013, 08:03 AM
Hello Michal,

Unfortunately this still is not supported. 

Regards,
Nik
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TreeListView
Asked by
Kevin
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Kevin
Top achievements
Rank 1
Tgaud
Top achievements
Rank 1
Michał
Top achievements
Rank 1
Nick
Telerik team
Share this question
or