Determining which column a control belongs in

7 posts, 1 answers
  1. Kai Hei Kok
    Kai Hei Kok avatar
    4 posts
    Member since:
    Oct 2009

    Posted 24 Nov 2009 Link to this post

    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
  2. Answer
    Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 30 Nov 2009 Link to this post

    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.
  3. DevCraft banner
  4. Kai Hei Kok
    Kai Hei Kok avatar
    4 posts
    Member since:
    Oct 2009

    Posted 30 Nov 2009 Link to this post

    can you provide some code examples for using the Visual tree?

    Thanks

    edit: nevermind, figured out the code : )
  5. Kai Hei Kok
    Kai Hei Kok avatar
    4 posts
    Member since:
    Oct 2009

    Posted 30 Nov 2009 Link to this post

    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.
  6. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 01 Dec 2009 Link to this post

    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.
  7. Kai Hei Kok
    Kai Hei Kok avatar
    4 posts
    Member since:
    Oct 2009

    Posted 01 Dec 2009 Link to this post

    Ok, once ive determined my business object, how do I traverse (or even get access to) the TreeListView?
  8. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 08 Dec 2009 Link to this post

    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.
Back to Top
DevCraft banner