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

NullReferenceException in RadTreeView when checking or unchecking node

10 Answers 356 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 09 Feb 2012, 12:00 PM
I get following exception when I check or unckec any node in RadTreeView.

System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.WinControls.UI.TreeNodeElement.ToggleElement_ToggleStateChanging(Object sender, StateChangingEventArgs args)
   at Telerik.WinControls.UI.RadToggleButtonElement.OnToggleStateChanging(StateChangingEventArgs e)
   at Telerik.WinControls.UI.TreeNodeCheckBoxElement.OnToggleStateChanging(StateChangingEventArgs e)
   at Telerik.WinControls.UI.RadToggleButtonElement.set_ToggleState(ToggleState value)
   at Telerik.WinControls.UI.TreeNodeCheckBoxElement.OnToggle()
   at Telerik.WinControls.UI.RadToggleButtonElement.OnClick(EventArgs e)
   at Telerik.WinControls.RadItem.DoClick(EventArgs e)
   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e)
   at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)
   at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)
   at Telerik.WinControls.UI.RadTreeView.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at Telerik.WinControls.RadControl.WndProc(Message& m)
   at Telerik.WinControls.UI.RadTreeView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Version is 2011.3 11.1219 
I can send you small sample with this exception. 
SergioB2
Top achievements
Rank 1
commented on 14 Jun 2022, 09:02 PM | edited

I know it's a little late for the answer, but I recently had to face the same error.  This happened to me, as in the other cases, when changing Telerik version from 2012 to 2015.

I have a DropDownList that when the SelectedIndexChanged event is fired, it fills the radTreeView with a DataSet.
This error NEVER happened to me when clicking on the treeview node the FIRST TIME, it ALWAYS happened to me when selecting another DropDownList item (AT THE SECOND TIME) and then clicking on any TreeView node.

After switching VisualStudio versions and .Net Framework versions and changing nothing at all, we made a seemingly insignificant change:

We placed this couple of lines of code BEFORE assigning the DataSource of the radTreeView:

radTreeView1.DataSource = Nothing
radTreeView1.Nodes.Clear()

 

And VoilĂ , it works!!!

Now, every time I change items in the DropDownList, I "reset" the database connection and clear the radTreeView nodes.

Sincerely, I hope this helps others.

10 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 09 Feb 2012, 03:34 PM
Hello,

I haven't been able to replicate your issue. Please could you post a small exmaple here (using the code formatting block) in full (no outside datasources) that will replicate the issue.
Thanks
Richard
0
Ilya
Top achievements
Rank 1
answered on 10 Feb 2012, 06:09 AM
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
namespace TestApp
{
    public partial class Form2 : Form
    {
        private readonly RadTreeView treeView;
         
        public Form2()
        {
            InitializeComponent();
 
            treeView = new RadTreeView
                       {
                           Dock = DockStyle.Fill,
                           CheckBoxes = true
                       };
            Controls.Add(treeView);
 
            Item root = new Item("Root");
            root.Childs.AddRange(new[]
                                 {
                                     new Item("Child 1"),
                                     new Item("Child 2"),
                                     new Item("Child 3"){Checked = true},
                                     new Item("Child 4"),
                                 });
            Initialize(root);
        }
 
        private void Initialize(Item root)
        {
            try
            {
                treeView.BeginUpdate();
                treeView.Nodes.Clear();
                FillTree(root, treeView.Nodes);
            }
            finally
            {
                treeView.EndUpdate();
            }
        }
 
        private void FillTree(Item item, RadTreeNodeCollection nodes)
        {
            RadTreeNode node = new RadTreeNode(item.Name)
                               {
                                   Checked = (item).Checked
                               };
            foreach (var child in item.Childs)
            {
                FillTree(child, node.Nodes);
            }
 
            nodes.Add(node);
        }
    }
 
    class Item
    {
        private readonly string _name;
        private readonly List<Item> _childs = new List<Item>();
        private bool _checked = false;
 
        public Item(string name)
        {
            _name = name;
        }
 
        public string Name
        {
            get { return _name; }
        }
 
        public bool Checked
        {
            get { return _checked; }
            set { _checked = value; }
        }
 
        public List<Item> Childs
        {
            get { return _childs; }
        }
    }
}
0
Jack
Telerik team
answered on 14 Feb 2012, 10:42 AM
Hi Ilya,

Thank you for sending us your code.

We are still not able to reproduce the issue when using our latest release - Q3 2011 SP1. Could you please describe the exact steps to reproduce the issue? Thank you for your cooperation.

I am looking forward to your reply.
 
Kind regards,
Jack
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Alex
Top achievements
Rank 1
answered on 14 Feb 2012, 11:24 AM
Please see the attached files. Here is the full text of error, you can see all assemblies here. Also I can email you project with referenced assemblies, if it helps.

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.


************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.WinControls.UI.TreeNodeElement.ToggleElement_ToggleStateChanging(Object sender, StateChangingEventArgs args)
   at Telerik.WinControls.UI.RadToggleButtonElement.OnToggleStateChanging(StateChangingEventArgs e)
   at Telerik.WinControls.UI.TreeNodeCheckBoxElement.OnToggleStateChanging(StateChangingEventArgs e)
   at Telerik.WinControls.UI.RadToggleButtonElement.set_ToggleState(ToggleState value)
   at Telerik.WinControls.UI.TreeNodeCheckBoxElement.OnToggle()
   at Telerik.WinControls.UI.RadToggleButtonElement.OnClick(EventArgs e)
   at Telerik.WinControls.RadItem.DoClick(EventArgs e)
   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e)
   at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)
   at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)
   at Telerik.WinControls.UI.RadTreeView.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at Telerik.WinControls.RadControl.WndProc(Message& m)
   at Telerik.WinControls.UI.RadTreeView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)




************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.239 (RTMGDR.030319-2300)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
TestApp
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///D:/Progging/testRadTreeChecking/TestApp/bin/Debug/TestApp.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.235 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.236 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
Telerik.WinControls.UI
    Assembly Version: 2011.3.11.1219
    Win32 Version: 2011.3.11.1219
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Telerik.WinControls.UI/2011.3.11.1219__5bb2a467cbec794e/Telerik.WinControls.UI.dll
----------------------------------------
Telerik.WinControls
    Assembly Version: 2011.3.11.1219
    Win32 Version: 2011.3.11.1219
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Telerik.WinControls/2011.3.11.1219__5bb2a467cbec794e/Telerik.WinControls.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.233 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
TelerikCommon
    Assembly Version: 2011.3.11.1219
    Win32 Version: 2011.3.11.1219
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/TelerikCommon/2011.3.11.1219__5bb2a467cbec794e/TelerikCommon.dll
----------------------------------------
qvpnb25m
    Assembly Version: 2011.3.11.1219
    Win32 Version: 4.0.30319.236 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
0
Jack
Telerik team
answered on 17 Feb 2012, 10:09 AM
Hi Alex,

Thank you for writing us back.

I managed to reproduce this issue. In my previous tests I used the wrong version - Q3 2011 2.11.831. This issue appears in version Q3 2011 SP1 3.11.1219. However, I am glad to inform you that the issue is addressed in Q1 2012 which we have just released and which is available at your account.

If you have other questions, do not hesitate to contact me.
 
Regards,
Jack
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Don
Top achievements
Rank 1
answered on 14 Mar 2012, 11:02 PM
And here I was thinking I was the only person this had happened to. Now we'll be able to try the Q1 2012 release!
0
Jack
Telerik team
answered on 16 Mar 2012, 05:01 PM
Hi Don,

Thank you for contacting us. Please write us if the issue continues to appear when using our latest release.
 
Greetings,
Jack
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Don
Top achievements
Rank 1
answered on 24 Apr 2012, 09:19 PM
Tried 2012 Q1 SP1 yesterday. The treeview now loads initially, but still eats a parameter when a child node is clicked. This is using the exact same code base that has a working treeview in 2011 Q2 SP2. We're rolling out this application in four weeks, so I do not have time to track down a root cause, find a workaround or create a sample project to reproduce the behavior.
0
Jack
Telerik team
answered on 27 Apr 2012, 12:43 PM
Hi Don,

It looks like the issue you are facing is slightly different from the one discussed in this thread. Could you please send us your project so we can debug and locate the issue. Thank you for your cooperation.

Please note that you have to open a new support ticket in order to be able to attach your project.

I am looking forward to your reply.
 
Greetings,
Jack
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Don
Top achievements
Rank 1
answered on 30 Apr 2012, 11:03 PM
As soon as I get a chance, I will.
Tags
Treeview
Asked by
Alex
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Ilya
Top achievements
Rank 1
Jack
Telerik team
Alex
Top achievements
Rank 1
Don
Top achievements
Rank 1
Share this question
or