Using two datatypes on a RadTreeListView

9 posts, 0 answers
  1. Kevin
    Kevin avatar
    4 posts
    Member since:
    Aug 2010

    Posted 01 Sep 2010 Link to this post

    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)
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Sep 2010 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kevin
    Kevin avatar
    4 posts
    Member since:
    Aug 2010

    Posted 02 Sep 2010 Link to this post

    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 :)
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Sep 2010 Link to this post

    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
  6. Kevin
    Kevin avatar
    4 posts
    Member since:
    Aug 2010

    Posted 02 Sep 2010 Link to this post

    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. 
  7. Tgaud
    Tgaud avatar
    58 posts
    Member since:
    Jun 2009

    Posted 15 Sep 2010 Link to this post

    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..
  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 15 Sep 2010 Link to this post

    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
  9. Michał
    Michał avatar
    1 posts
    Member since:
    Dec 2010

    Posted 20 May 2013 Link to this post

    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.
  10. Nick
    Admin
    Nick avatar
    593 posts

    Posted 23 May 2013 Link to this post

    Hello Michal,

    Unfortunately this still is not supported. 

    Regards,
    Nik
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready