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

Applying row style according to row hierarchy level

1 Answer 92 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 29 Oct 2010, 05:05 PM
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

1 Answer, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 04 Nov 2010, 01:02 PM
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
Tags
TreeListView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or