When GridView has a GridViewComboBoxColumn that is bound to a list of objects and that list changes a null reference error is thrown. This error did not get throw in the previous release (2013 Q1), it just started happening in (2013 Q2, specifically 2013.2.612.40).
Here is a code example using a list of Authors and a list of books. Basically the book object has a reference to the Author object. When the author list changes the book grid will throw a null reference error.
Here is the stack trace of the error:
at Telerik.WinControls.UI.GridViewComboBoxColumn.AddItem(Int32 i)
at Telerik.WinControls.UI.GridViewComboBoxColumn.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.Child_PropertyChanged(Object sender, PropertyChangedEventArgs e)
at GridTest.Author.NotifyPropertyChanged(String info) in c:\Users\SESA124669\Documents\Visual Studio 2012\Projects\GridTest\GridTest\Form1.cs:line 69
at GridTest.Author.set_Name(String value) in c:\Users\SESA124669\Documents\Visual Studio 2012\Projects\GridTest\GridTest\Form1.cs:line 97
at GridTest.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\SESA124669\Documents\Visual Studio 2012\Projects\GridTest\GridTest\Form1.cs:line 52
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at GridTest.Program.Main() in c:\Users\SESA124669\Documents\Visual Studio 2012\Projects\GridTest\GridTest\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Here is the code:
Here is a code example using a list of Authors and a list of books. Basically the book object has a reference to the Author object. When the author list changes the book grid will throw a null reference error.
Here is the stack trace of the error:
at Telerik.WinControls.UI.GridViewComboBoxColumn.AddItem(Int32 i)
at Telerik.WinControls.UI.GridViewComboBoxColumn.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.Child_PropertyChanged(Object sender, PropertyChangedEventArgs e)
at GridTest.Author.NotifyPropertyChanged(String info) in c:\Users\SESA124669\Documents\Visual Studio 2012\Projects\GridTest\GridTest\Form1.cs:line 69
at GridTest.Author.set_Name(String value) in c:\Users\SESA124669\Documents\Visual Studio 2012\Projects\GridTest\GridTest\Form1.cs:line 97
at GridTest.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\SESA124669\Documents\Visual Studio 2012\Projects\GridTest\GridTest\Form1.cs:line 52
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at GridTest.Program.Main() in c:\Users\SESA124669\Documents\Visual Studio 2012\Projects\GridTest\GridTest\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Here is the code:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using Telerik.WinControls.UI;namespace GridTest{ public partial class Form1 : Form { private BindingList<Author> AuthorData = new BindingList<Author>(); private BindingList<Book> BookData = new BindingList<Book>(); public Form1() { InitializeComponent(); radGridViewAuthors.DataSource = AuthorData; radGridViewBooks.MasterTemplate.Columns.Clear(); GridViewComboBoxColumn colAuth = new GridViewComboBoxColumn("Author"); colAuth.HeaderText = "Author"; colAuth.Name = "Author"; colAuth.DataSource = AuthorData; colAuth.ValueMember = "Id"; colAuth.DisplayMember = "Name"; colAuth.DisplayMemberSort = true; radGridViewBooks.MasterTemplate.Columns.Add(colAuth); GridViewTextBoxColumn colName = new GridViewTextBoxColumn("Name"); colName.HeaderText = "Name"; colName.Name = "Name"; colName.ReadOnly = true; radGridViewBooks.MasterTemplate.Columns.Add(colName); radGridViewBooks.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; radGridViewBooks.DataSource = BookData; } private void button1_Click(object sender, EventArgs e) { Author m = new Author(); m.Id = AuthorData.Count + 1; AuthorData.Add(m); m.Name = textBoxAuthorName.Text; } private void button2_Click(object sender, EventArgs e) { Book m = new Book(textBoxBookName.Text); BookData.Add(m); } } public class Author : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } private int id; public int Id { get { return id; } set { id = value; NotifyPropertyChanged("Id"); } } private string name; public string Name { get { return name; } set { name = value; NotifyPropertyChanged("Name"); } } public Author() { } public Author(int id, string name) { Id = id; Name = name; } } public class Book : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } private string name; public string Name { get { return name; } set { name = value; NotifyPropertyChanged("Name"); } } private Author author; public Author Author { get { return author; } set { author = value; NotifyPropertyChanged("Author"); } } public Book() { } public Book(string name) { Name = name; } }}