RadTreeViewItem Custonm Attributes

5 posts, 1 answers
  1. Shaikh Ahmad
    Shaikh Ahmad avatar
    20 posts
    Member since:
    Oct 2012

    Posted 11 Mar 2010 Link to this post

    Hye,

    Is there any way i can bind custom values to a RadTreeViewItem.
    This is what i'm trying to achieve

    Public class Person
    {
        public Guid Id { get; set;}
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string City { get; set; }
    }

    RadTreeViewItem nodePerson = new RadTreeViewItem();
    ? = Person.Id
    nodePerson.Header = Person.FirstName + Person.LastName;
    ? = Person.City

    Are there any container for all these custom attributes?

    Thanks,
    Shaikh

  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 16 Mar 2010 Link to this post

    Hello Shaikh Ahmad,

    You can use a DataTemplate when determining how to display your business objects inside the RadTreeView.

    I have prepared an example for you, illustrating how you can use HierarchicalDataBinding when displaying your RadTreeViewItems.

    I used a StackPanel in the DataTemplate of my Employee business object (employeeTemplate) and displayed the Id, FirstName, LastName and the City of the employees in TextBlocks.

    Please take a look at the example and let me know if you need more info.

    Sincerely yours,
    Tina Stancheva
    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. Shaikh Ahmad
    Shaikh Ahmad avatar
    20 posts
    Member since:
    Oct 2012

    Posted 17 Mar 2010 Link to this post

    Thanks,

    The example helped me a bit... But my main concern is to display FirstName and LastName only...
    As for the Id, I'd like to bind it to a property that is not visible and can be retrieved back from code behind...

    Any ideas?

    Regards,
    Shaikh
  4. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 22 Mar 2010 Link to this post

    Hi Shaikh Ahmad,

    When you data-bind an ItemsControl like RadTreeView to a collection of business objects, each source object is dynamically wrapped in a container (RadTreeViewItem in your case). These automatically generated containers are used for visualizing the raw data in your data source. The DataTemplates you specify determine how your data will be rendered - in your case you only need to visualize two of the properties of the business objects. Thus, you only need to bind to these two properties in the DataTemplate you specify. However, although they are not visualized, the rest of the properties of your business objects are still accessible via the RadTreeView.Items collection. The important distinction to make here is that the RadTreeView.Items collection contains your raw business objects, and not the dynamically generated containers of type RadTreeViewItem. So, if you want to access a business object after the TreeView has been rendered on the screen, you can do so with a statement like the one below:

    MyDataItem item = myTreeView.Items[2] as MyDataItem;

    I modified the example by displaying  only the FirstName and the LastName of each employee in the RadTreeView items.

    I also added a TextBlock that displays the ID of the selected employee (if  an employee is selected). I accessed the ID through the SelectedItem property of the RadTreeViewItem.

    Regards,
    Tina Stancheva
    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.
  5. Shaikh Ahmad
    Shaikh Ahmad avatar
    20 posts
    Member since:
    Oct 2012

    Posted 22 Mar 2010 Link to this post

    Thanks a lot....
    This is exactly what i needed...
Back to Top