Binding Grid to a sub class property

6 posts, 0 answers
  1. Alessandro
    Alessandro avatar
    31 posts
    Member since:
    Oct 2010

    Posted 07 Feb 2011 Link to this post

    I am binding a grid to a list of objects such as:

    ObservableCollection<ListItem> List

    Wherby the ListItem is defined as:

    public class ListItem
    {
      public int Id;
      public string Title;
      // some other properties
      public Item TheItem;
    }


    the class "Item" is defined as:

    public class Item
    {
       public string Name;
       public string Location;
       public string Brand;
       public string Area;
    }

    Question 1

      I am binding my grid to the List of ListItems and therefore want to show its properties. I also want to show properties of the Item class it contains. My thinking is that the only way to do this is to dynamically construct the columns and bind them programatically. Am I correct in this thinking?

    Question 2
     
      I am using a selector for specifing the detail panes. These Detail pains are setup to bind to an Item class, NOT to a ListItem class (this is becuase I reuse the usercontrol elswhere). Can I modify the binding of the Detail item so that it does not bind to the default ListItem (to which the grid items bind) but rather to a contained object of the ListItem? How and where would I do this? Thanks for all your help!

     -- xavier
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 08 Feb 2011 Link to this post

    Hello Xavier,

    You can bind the columns easily by using:

    DataMemberBinding={Binding Item.Name}
    DataMemberBinding={Binding Item.Location}, etc.

    As for question 2 - do you mean the Row Details? If so, I am afraid this is not possible. The DataContext of the details presenter would be of type ListItem and you cannot change that. So, you could use the same Binding as the columns in this case.

    Kind regards,
    Veselin Vasilev
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. sumit
    sumit avatar
    3 posts
    Member since:
    Dec 2010

    Posted 02 Feb 2012 Link to this post

    hi Veselin,

    With your example below:
    DataMemberBinding={Binding Item.Name}
    DataMemberBinding={Binding Item.Location}, etc.

    I am noticing if I do this, then these two columns are no longer sortable, and we can not filter them either. Is this a known functionality? What is the workaround? Please advice.

    Thanks.
  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 03 Feb 2012 Link to this post

    Hello,

     Are you using our latest official version - Q3 2011 SP1?

    Greetings,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  5. sumit
    sumit avatar
    3 posts
    Member since:
    Dec 2010

    Posted 03 Feb 2012 Link to this post

    Yes.
  6. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 03 Feb 2012 Link to this post

    Hi,

    I've made a small project in order to reproduce the issue but sorting and filtering work as expected. Can you confirm that your scenario is the same? Is there something specific that I have missed?
     
    Greetings,
    Yordanka
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top