Applying row style according to row hierarchy level

2 posts, 0 answers
  1. Andrew
    Andrew avatar
    1 posts
    Member since:
    Oct 2010

    Posted 29 Oct 2010 Link to this post

    I'm trying to apply row styles to my RadTreeListView depending on the hierarchy level of the row. Basically, I want all top level rows to be have a bold font weight, but all other rows to be normal. Below is the StyleSelector I am using:

    public class RowStyleSelector : StyleSelector
    {
        public Style TopLevelRowStyle { getset; }
        public Style DetailRowStyle { getset; }

        public override Style SelectStyle(object item, DependencyObject container)
        {
            if (container.GetType() == typeof(TreeListViewRow))
            {
                TreeListViewRow row = (TreeListViewRow)container;

                if (row.Level == 0)
                    return TopLevelRowStyle;
                else
                    return DetailRowStyle;
            }      
             return DetailRowStyle;
        }
    }

    However, I get a NullReferenceException when trying to access the Level property of the TreeListViewRow. This is the stack trace:

    {System.NullReferenceException: Object reference not set to an instance of an object.
       at Telerik.Windows.Controls.TreeListView.TreeListViewRow.get_Level()
       at SEDashboard.Controls.RowStyleSelector.SelectStyle(Object item, DependencyObject container)
       at Telerik.Windows.Controls.GridView.GridViewDataControl.ApplyRowStyle(GridViewRow row)
       at Telerik.Windows.Controls.GridView.GridViewDataControl.PrepareContainerForItemOverride(DependencyObject element, Object item)
       at Telerik.Windows.Controls.RadTreeListView.PrepareContainerForItemOverride(DependencyObject element, Object item)
       at Telerik.Windows.Controls.GridView.BaseItemsControl.Telerik.Windows.Controls.GridView.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
       at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
       at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled)
       at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.InsertNewContainer(Int32 childIndex, UIElement container)
       at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized)
       at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)}


    What am I doing wrong?

    Thanks,

    Andrew
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 04 Nov 2010 Link to this post

    Hello Andrew,

    This is probably a bug and I have logged it in our public issue tracking system. You can check its status here.

    As a workaround, you can create a Level property of your business object and select the style based on its value. The first parameter of the SelectStyle method is your business object.

    I have updated your Telerik points.

    Best wishes,
    Veselin Vasilev
    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. DevCraft banner
Back to Top