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

RadTreeViewItem Custonm Attributes

4 Answers 48 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Shaikh Ahmad
Top achievements
Rank 1
Shaikh Ahmad asked on 11 Mar 2010, 06:02 PM
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

4 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 16 Mar 2010, 05:07 PM
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.
0
Shaikh Ahmad
Top achievements
Rank 1
answered on 17 Mar 2010, 09:18 AM
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
0
Accepted
Tina Stancheva
Telerik team
answered on 22 Mar 2010, 02:43 PM
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.
0
Shaikh Ahmad
Top achievements
Rank 1
answered on 23 Mar 2010, 03:27 AM
Thanks a lot....
This is exactly what i needed...
Tags
TreeView
Asked by
Shaikh Ahmad
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Shaikh Ahmad
Top achievements
Rank 1
Share this question
or