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

RadTreeView.ContainerFromItemRecursive returning null

1 Answer 164 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 21 Oct 2015, 10:26 AM

I have a RadTreeView that I am expanding by applying a style.

<Style TargetType="{x:Type telerik:RadTreeViewItem}">
            <EventSetter Event="Selected" Handler="TreeViewItem_Selected" />
            <Setter Property="IsExpanded" Value="True"></Setter>
        </Style>

 

I am trying to display checkboxes next to items that meet a certain condition. To do this I am trying to hide the checkboxes on those elements that do not meet the condition.

I am hooking into the loaded event of my RadTreeView and trying to iterate down through the items, get the item container and hide the checkbox if necessary.

The problem I am having is that ContainerFromItemRecursive is returning null for any item that is not at the root level.

Here's my code.

private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
        {
            RadTreeView rtv = sender as RadTreeView;
 
            foreach (IMeasurementTreeBase item in rtv.Items)
                        {
                            SetCheckBoxVisibilityRecursive(item, rtv);
                        }
            }
        }
 
        public void SetCheckBoxVisibilityRecursive(IMeasurementTreeBase item, RadTreeView rtv)
        {
            if (!item.HasMeasurements())
            {
                RadTreeViewItem treeItem = rtv.ContainerFromItemRecursive(item);
 
                if (treeItem != null)
                {
                    var children = treeItem.ChildrenOfType<CheckBox>().ToList();
 
                    children[0].Visibility = Visibility.Collapsed;
                }
 
                foreach (IMeasurementTreeBase subItem in item.Children)
                {   
                    SetCheckBoxVisibilityRecursive(subItem, rtv);
                }
            }
        }

 

Thanks

 

1 Answer, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 21 Oct 2015, 03:48 PM

Managed to achieve what I wanted by using this very useful article.

 

http://docs.telerik.com/devtools/wpf/controls/radtreeview/how-to/howto-tri-state-mvvm.html

Tags
TreeView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Share this question
or