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

Editing/filtering on RadGrid Crash the application, with System.Argument null exception

1 Answer 129 Views
GridView
This is a migrated thread and some comments may be shown as answers.
daniel
Top achievements
Rank 1
daniel asked on 28 Jul 2008, 08:39 PM
I am trying to use the RadDataGrid view, with the autoGenerateColumn Property set to false, I added three columns as follows.          

radGridView1.Columns.Add(new
Telerik.WinControls.UI.GridViewDataColumn("ProductId"));
radGridView1.Columns.Add(new Telerik.WinControls.UI.GridViewDataColumn("ProductName"));
radGridView1.Columns.Add(new Telerik.WinControls.UI.GridViewDataColumn("UnitPrice"));

and then i bounded the data source to list<Products>

When I run the application and try to edit any of the fields or if I try to type in the filter box the application crashes with the following exception. While investigating the problem I found out that the default editor for the columns is never instantiated and is set to null

radGridView1.Columns["ProductId"].GetDefaultEditor()==null

Sample Code
-----------

  public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            radGridView1.MasterGridViewTemplate.AutoGenerateColumns = false; //disable auto generate columns

            radGridView1.EnableFiltering = true; //enable filter           

            radGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

            //Add columns

            radGridView1.Columns.Add(new Telerik.WinControls.UI.GridViewDataColumn("ProductId"));

            radGridView1.Columns.Add(new Telerik.WinControls.UI.GridViewDataColumn("ProductName"));

            radGridView1.Columns.Add(new Telerik.WinControls.UI.GridViewDataColumn("UnitPrice"));           

            //Bind data           

            radGridView1.DataSource = GetProductList();

        }

        public List<Product> GetProductList()

        {

            var products = new List<Product>();

            products.Add(new Product("PRD-001", "Betty Crocker® Angel Food Cake Mix", 8.65));

            products.Add(new Product("PRD-002", "Betty Crocker Complete Desserts®", 8));

            products.Add(new Product("PRD-003", "Betty Crocker® Cookie Mix", 1.25));

            products.Add(new Product("PRD-004", "Betty Crocker® Frosting", 4.00));

            products.Add(new Product("PRD-005", "Betty Crocker® Sunkist® Lemon Bars", 10.00));

            products.Add(new Product("PRD-006", "Betty Crocker® Supreme Brownie Mix", 2.00));

            products.Add(new Product("PRD-007", "Betty Crocker® Variety Dessert Mixes", 3.55));

            products.Add(new Product("PRD-008", "Betty Crocker® Warm Delights® Desserts", 4.49));

            return products;

        }

    }

    public class Product

    {

        public Product()

        {

        }

        public Product(string id, string name, double price)

        {

            this.ProductId = id;

            this.ProductName = name;

            this.UnitPrice = price;

        }

        public string ProductId { get; set; }

        public string ProductName { get; set; }

        public double UnitPrice { get; set; }

    }

EXception Detail
-----------------------
System.ArgumentNullException was unhandled
  Message="Value cannot be null.\r\nParameter name: key"
  Source="mscorlib"
  ParamName="key"
  StackTrace:
       at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
       at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
       at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
       at Telerik.WinControls.UI.GridViewEditManager.GetDefaultEditor(IEditorProvider provider)
       at Telerik.WinControls.UI.BaseGridBehavior.InitializeEditor(RadGridView grid, GridViewColumn column)
       at Telerik.WinControls.UI.GridDataCellElement.item_Click(Object sender, EventArgs e)
       at Telerik.WinControls.RadItem.OnClick(EventArgs e)
       at Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e)
       at Telerik.WinControls.UI.RadMenuItemBase.OnClick(EventArgs e)
       at Telerik.WinControls.UI.RadMenuItem.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.RadElement.CallDoMouseUp(MouseEventArgs e)
       at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)
       at Telerik.WinControls.RadControl.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.RadPopupControl.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(Int32 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 RadGridViewTest.Program.Main() in C:\Documents and Settings\ddebela\My Documents\Visual Studio 2008\Projects\RadGridViewTest\RadGridViewTest\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(Assembly 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.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

1 Answer, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 30 Jul 2008, 11:27 AM
Hello Daniel,

That is because the GridViewDataColumn is too generic and it does not "know" what is the default editor and how to provide it. When adding columns to RadGridView you should use specific columns like GridViewTextBoxColumn that can provide an editor. You can take a look at this page of the online help for more information about adding columns to RadGridView.

Kind regards,
Jordan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
daniel
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Share this question
or