Completed
Last Updated: 22 Feb 2016 07:59 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 05 Nov 2015 08:26
Category: TreeView
Type: Bug Report
3
FIX. RadTreeView - StackOverflowException when using LazyMode and no nodes are defined in NodesNeeded event
To reproduce:

public Form1()
{
    InitializeComponent();
    this.radTreeView1.LazyMode = true; 
    this.radTreeView1.NodesNeeded+=radTreeView1_NodesNeeded;
}

private void radTreeView1_NodesNeeded(object sender, Telerik.WinControls.UI.NodesNeededEventArgs e)
{
    
}

Workaround: set the AllowArbitraryItemHeight property to true.
3 comments
ADMIN
Ivan Todorov
Posted on: 11 Nov 2015 11:52
Hello,

We have reviewed the case further, and we've found another workaround which should work in all cases. It involves overriding a single method of RadTreeViewElement, but you also need to create a derived class of RadTreeView in order to plug the custom element:

        public class MyTreeViewElement : RadTreeViewElement
        {
            protected override void UpdateScrollersOnNodesNeeded(RadTreeNode node)
            {
                var nodesField = node.GetType().GetField("nodes", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                RadTreeNodeCollection nodes = nodesField.GetValue(node) as RadTreeNodeCollection;
                if (nodes != null && nodes.Count > 0)
                {
                    base.UpdateScrollersOnNodesNeeded(node);
                }
            }

            protected override Type ThemeEffectiveType
            {
                get
                {
                    return typeof(RadTreeViewElement);
                }
            }
        }

        public class MyTreeView : RadTreeView
        {
            protected override RadTreeViewElement CreateTreeViewElement()
            {
                return new MyTreeViewElement();
            }

            public override string ThemeClassName
            {
                get
                {
                    return typeof(RadTreeView).FullName;
                }
                set
                {
                    base.ThemeClassName = value;
                }
            }
        }

After you have this, you need to go through your Designer files and replace "new Telerik.WinControls.UI.RadTreeView();" with "new MyTreeView()";

We do understand the importance of this case, however, for the time being, we do not plan releasing an internal build for it, as adopting the workaround is easier than working with an internal build. However, depending on the reports, we might consider releasing an internal build in future. For now, the issue is scheduled for the next official release.
erwin
Posted on: 10 Nov 2015 12:17
Hi Matthias, 
the NodesNeeded event handler is triggered even when LazyMode = false. The workaround that works with my trees is to de-register the event handler  when LazyMode is not needed. The order of the statements is important.

When using LazyMode, it' important to set
AllowArbitraryItemHeight to true.

If you don't need LazyMode, just remove the NodesNeeded handler.

Toggle LazyMode to false:

                if (this.softwareRadTreeView.LazyMode == true)
                {
                    //TODO: 2015Q3SP1 if lazymode set to false before removing the event handler, a stack overflow happens
                    this.softwareRadTreeView.NodesNeeded -= this.softwareRadTreeView_NodesNeeded;
                    this.softwareRadTreeView.LazyMode = false;
                }

// toggle lazy mode to true

             if (this.softwareRadTreeView.LazyMode == false)
                {
                    this.softwareRadTreeView.LazyMode = true;
                    this.softwareRadTreeView.NodesNeeded += this.softwareRadTreeView_NodesNeeded;
                }

I also support the idea of Telerik releasing a fix for this before 2016Q1 since it makes LazyMode in RadTreeView virtually unusable without consulting Telerik Support.

Matthias
Posted on: 10 Nov 2015 11:57
This bug happens also with LazyMode=false.

I've tried the workaround with LazyMode = false
The workaround is is not working. The SW run into a stack overflow again.

This is very critical, since the complete RadTreeView is usable anymore. Probably you you provide an intermediate update for that component.

Thanks