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

Determining which column a control belongs in

6 Answers 142 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Kai Hei Kok
Top achievements
Rank 1
Kai Hei Kok asked on 24 Nov 2009, 07:36 PM
Hi all, im trying to use the TreeListView control to input data,

The hierarchy for my tree is built using the nested forloop statements (_directors, _managers, _employees) seen below.
There is one column that displays the tree, and more columns are generated based on the elements in _departments.

 
private RadTreeListView void ConstructTile()  
{  
    RadTreeListView radTreeListView = new RadTreeListView();  
    radTreeListView.ItemTemplate = _radRootItem;  
    radTreeListView.Columns.Add(new RadColumn { CellTemplate = _radItem, PropertyName = "Name", Header = "Hierarchy" });  
    foreach (Department department in _departments)  
    {  
        radTreeListView.Columns.Add(new RadColumn { CellTemplate = _radDepartmentItem, PropertyName = department.Name, Header = department.Name });  
    }  
 
    foreach (Director director in _directors)  
    {  
        RadTreeListViewItem radTreeListViewItemDirector = new RadTreeListViewItem();  
        radTreeListViewItemDirector.DataContext = director;  
 
        foreach (Manager manager in _managers)  
        {  
            RadTreeListViewItem radTreeListViewItemBuildManager = new RadTreeListViewItem();  
            radTreeListViewItemBuildManager.DataContext = manager;  
 
            foreach (Employee employee in _employees)  
            {  
                RadTreeListViewItem radTreeListViewItemEmployee = new RadTreeListViewItem();  
                radTreeListViewItemEmployee.DataContext = employee;  
                radTreeListViewItemBuildManager.Items.Add(radTreeListViewItemEmployee);  
            }  
            radTreeListViewItemDirector.Items.Add(radTreeListViewItemBuildManager);  
        }  
        radTreeListView.Items.Add(radTreeListViewItemDirector);  
    }  
    return radTreeListView;  

The cell templates used are defined in xaml
<telerik:HierarchicalDataTemplate x:Key="RadItem">  
    <TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>  
</telerik:HierarchicalDataTemplate> 
 
<telerik:HierarchicalDataTemplate x:Key="RadRootItem" ItemsSource="{Binding Items}"/>  
 
<telerik:HierarchicalDataTemplate x:Key="RadDepartmentItem">  
    <CheckBox VerticalAlignment="Center" HorizontalAlignment="Center"/>  
</telerik:HierarchicalDataTemplate> 
 

The generated columns for _departments uses the "RadDepartmentItem" template which contains a checkbox. I want to be able to determine which row and column my a checkbox belongs to when I click it. Currently, I am able to determine which row it belongs to (using DataContext) but I am unable to determine the column it is in. Is there a way to do this?

Thanks!

Arthur

6 Answers, 1 is accepted

Sort by
0
Accepted
Miroslav
Telerik team
answered on 30 Nov 2009, 12:38 PM
Hi Kai Hei Kok,

Thank you for evaluating the RadTreeList control.

There are several ways in which you can do this.

1. You go down the Visual Tree from the CheckBox until you reach the RadCell control, then you can get its Column and ColumnContainer properties.

You can get the visual parent of an object by using the:
VisualTreeHelper.GetParent(visual). method.

2. You can assign a different template for each column and then bind one of the properties of the checkbox to one of the properties on your objects. For example you can bind the Tag property to a colelction of departments found on each object:
<CheckBox Tag="{Binding Departments[2]}" />

In your case the first suggestion will involve less changes.

Best wishes,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kai Hei Kok
Top achievements
Rank 1
answered on 01 Dec 2009, 02:00 AM
can you provide some code examples for using the Visual tree?

Thanks

edit: nevermind, figured out the code : )
0
Kai Hei Kok
Top achievements
Rank 1
answered on 01 Dec 2009, 02:46 AM
i guess one more question i have is:

After ive identified the RadCell, is there anyway to find every child checkbox in the treelist hierarchy of the same column which the RadCell is located in?

for example, if i checked the box on a 'Manager' treeitem, i want all the checkboxes of the same column for every 'Employee' under that Manager to also be checked.
0
Miroslav
Telerik team
answered on 01 Dec 2009, 02:48 PM
Hello Kai Hei Kok,

Unfortunately finding and checking all descendant CheckBoxes will not be trivial.

The reason for this is the TreeList Virtualization. Currently we try to generate visual items only when needed, i.e. only for the items that are visible to the user. It is quite possible that you will have more business objects and some of them will not be visible. Therefore there will not be enough generated items.

In this case it is better to mark properties on your business objects as checked, then you will not have the problem of item generation. So once you get a reference you your Manger business object you will have to be able to find their child nodes and set the respective properties there.

Do you think this will work in your case?

All the best,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kai Hei Kok
Top achievements
Rank 1
answered on 01 Dec 2009, 08:48 PM
Ok, once ive determined my business object, how do I traverse (or even get access to) the TreeListView?
0
Miroslav
Telerik team
answered on 08 Dec 2009, 11:50 AM
Hello Kai Hei Kok,

Ideally, you should not need to work with the TreeList at all.

Since the CheckBoxes will be bound in the CellTemplate, changing the property on the business object will be enough.

If you need to set or get a property on the cell or the item it may be better to use ContaienrBindings to set them.

Do you think this will work in your case?

All the best,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeListView
Asked by
Kai Hei Kok
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Kai Hei Kok
Top achievements
Rank 1
Share this question
or