Completed
Last Updated: 19 Jan 2016 10:45 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 30 Dec 2015 14:33
Category: TreeView
Type: Bug Report
0
FIX. RadTreeView - NullReferenceException when calling the BeginEdit method for a specific child RadTreeNode
When you open the last node for edit programmatically, either an exception is thrown or the editor is not opened.

Steps to reproduce:

1. Drag a RadTreeView from Toolbox and drop it onto the form.
2. Set the size of RadTreeView at design time to Size(354, 248).
3. Add a RadButton.
4. Use the following code:
public Form1()
{
    InitializeComponent(); 
    radTreeView1.AllowEdit = true; 
    radTreeView1.Nodes.Add("Root");
    for (int i = 0; i < 20; i++)
    {
        radTreeView1.Nodes[0].Nodes.Add("Test" + i.ToString());
    }
}

private void radButton1_Click(object sender, EventArgs e)
{
    RadTreeNode node = new RadTreeNode("Demo" + radTreeView1.Nodes[0].Nodes.Count.ToString());
    radTreeView1.Nodes[0].Nodes.Add(node);
    node.BeginEdit();
}

5. Click the button.
6. Collapse the root node.
7. Click the button again.



Workaround:

        private void button1_Click(object sender, EventArgs e)
        {
            RadTreeNode node = new RadTreeNode("Demo" + radTreeView1.Nodes[0].Nodes.Count.ToString());
            radTreeView1.Nodes[0].Nodes.Add(node);
            this.radTreeView1.TreeViewElement.Update(RadTreeViewElement.UpdateActions.Reset);
            node.Parent.Expanded = true;
            ((MyTreeViewElement)this.radTreeView1.TreeViewElement).SuspendEndEdit = true;
            node.BeginEdit();
            ((MyTreeViewElement)this.radTreeView1.TreeViewElement).SuspendEndEdit = false;
        } 

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

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

    public class MyTreeViewElement : RadTreeViewElement
    {
        public bool SuspendEndEdit = false;

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

        protected override bool EndEditCore(bool commitChanges)
        {
            if (SuspendEndEdit)
            {
                return false;
            }

            return base.EndEditCore(commitChanges);
        }
    }
0 comments