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

Cannot explain crash of grid (null object reference exception from grid)

6 Answers 165 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fred
Top achievements
Rank 1
Fred asked on 13 Oct 2010, 03:28 PM
Hello,

I've got this problem using GridView, where when ShowRowHeaderColumn is false my grid crashes with a null object reference exception somewhere from within GridView. The example below is the simplest test case of the problem I could find, it is a grid with 1 child subgrid, when opening the child level and selecting a row, then moving it out of view and back into view by scrolling the grid crashes. I don't think this problem is widespread, because surely someone else must be setting ShowRowHeaderColumn to false in a hierarchic grid and then I would have found something about this problem, so it must be something I do wrong. It is however the most simple example I could come up with, so I'm kinda stuck.

TestGridForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
using Telerik.WinControls.UI;
using Telerik.WinControls.Enumerations;
 
namespace RadGridViewProblems
{
    /*
     * Demonstate a gridview crash problem when quickly scrolling up and down and having row header column disabled, set
     * ShowRowHeaderColumn below to true and no crash anymore, reason why/workaround: unknown
     */
 
    public partial class TestGridForm : RadForm
    {
        public TestGridForm()
        {
            InitializeComponent();
 
            this.Load += new EventHandler(FormLoaded);
        }
 
        private void FormLoaded(object sender, EventArgs e)
        {
            //testGridView.ReadOnly = true;
            testGridView.AutoGenerateColumns = true;
 
            childGridViewTemplate = new GridViewTemplate();
            childGridViewTemplate.AutoGenerateColumns = true;
 
            //set ShowRowHeaderColumn here to true and no crash anymore
            testGridView.MasterTemplate.ShowRowHeaderColumn = true;
 
            //the one on the child template can be true/false, it doesn't matter
            childGridViewTemplate.ShowRowHeaderColumn = false;
 
            testGridView.MasterTemplate.Templates.Add(childGridViewTemplate);
 
            GridViewRelation relation = new GridViewRelation(testGridView.MasterTemplate);
            relation.ChildTemplate = childGridViewTemplate;
            relation.RelationName = "ParentChildren";
            relation.ParentColumnNames.Add("id");
            relation.ChildColumnNames.Add("parent_id");
 
            testGridView.Relations.Add(relation);
 
            LoadData();
        }
 
        private void LoadData()
        {
            List<MyParentClass> myParentList = new List<MyParentClass>();
            for(int i=1; i<=100; i++)
            {
                myParentList.Add(new MyParentClass() { id = i, name = i.ToString(), info = "blabla" });
            }
 
            List<MyChildClass> myChildList = new List<MyChildClass>();
            Random random = new Random(1);
            for(int i=1; i<=300; i++)
            {
                myChildList.Add(new MyChildClass() { parent_id = random.Next(1,100), id = i, name = i.ToString(), info = "blabla" });
            }
 
            testGridView.DataSource = myParentList;
            childGridViewTemplate.DataSource = myChildList;
        }
 
        private GridViewTemplate childGridViewTemplate;
    }
 
    public class MyParentClass
    {
        public int id { get; set; }
        public String name { get; set; }
        public String info { get; set; }
    }
 
    public class MyChildClass
    {
        public int parent_id { get; set; }
        public int id { get; set; }
        public String name { get; set; }
        public String info { get; set; }
    }
}

TestGridForm.Designer.cs
namespace RadGridViewProblems
{
    partial class TestGridForm
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if(disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.testGridView = new Telerik.WinControls.UI.RadGridView();
            ((System.ComponentModel.ISupportInitialize)(this.testGridView)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            this.SuspendLayout();
            //
            // testGridView
            //
            this.testGridView.Dock = System.Windows.Forms.DockStyle.Fill;
            this.testGridView.Location = new System.Drawing.Point(0, 0);
            //
            // testGridView
            //
            this.testGridView.Name = "testGridView";
            this.testGridView.Padding = new System.Windows.Forms.Padding(0, 0, 0, 1);
            //
            //
            //
            this.testGridView.RootElement.Padding = new System.Windows.Forms.Padding(0, 0, 0, 1);
            this.testGridView.Size = new System.Drawing.Size(833, 444);
            this.testGridView.TabIndex = 0;
            this.testGridView.Text = "radGridView1";
            //
            // TestGridForm
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(833, 494);
            this.Controls.Add(this.testGridView);
            this.Name = "TestGridForm";
            this.Padding = new System.Windows.Forms.Padding(0, 0, 0, 50);
            //
            //
            //
            this.RootElement.ApplyShapeToControl = true;
            this.Text = "Test Form";
            ((System.ComponentModel.ISupportInitialize)(this.testGridView)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
            this.ResumeLayout(false);
 
        }
 
        #endregion
 
        private Telerik.WinControls.UI.RadGridView testGridView;
 
    }
}

If someone could point me to my mistake (or who knows confirm it's a bug in GridView) that would be great.

Thanks
cheers
Frederik

6 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 13 Oct 2010, 04:10 PM
Hi Fred, 

I have tried setting the property on both a MasterTemplate and a ChildTemplate and I can't replicate your issue when doing what you described. 
I see from your code you must be using one of the later versions of the controls (what is the exact version?)
Richard
0
Fred
Top achievements
Rank 1
answered on 13 Oct 2010, 04:34 PM
Hi Richard,

thanks for your reply, you did have to change the line
this.gridSearchResult.MasterTemplate.ShowRowHeaderColumn = true;
to
this.gridSearchResult.MasterTemplate.ShowRowHeaderColumn = false;
to demonstrate the problem, I had forgotten to do that in my example.

I have been able to reproduce this on a colleague's computer. About the version, the reference to GridView says in properties a version of v2.0.50727, the installer was called RadControls_WinForms_2010_2_10_806_dev (should be the last version available I think). But hearing that you cannot reproduce the problem does suggest it is some version specific bug, unless you have the same version then something else must be different. If you have some more ideas, much appreciated.

Thanks
Frederik
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 13 Oct 2010, 04:49 PM
Hi, 

Still not been able to replicate it. the latest version is 914 by the way which you'll find in your downloads area. 
I understand there were quite a few fixes in that release. 
Hope that helps
Richard
0
Fred
Top achievements
Rank 1
answered on 13 Oct 2010, 05:10 PM
Ok, I'll check if the update fixes the problem.

Thanks
Frederik
0
Fred
Top achievements
Rank 1
answered on 19 Nov 2010, 04:37 PM
Hi,

I can confirm this is fixed in 2010 Q3 :)

Greetings
Frederik
0
Richard Slade
Top achievements
Rank 2
answered on 19 Nov 2010, 04:41 PM
Glad that solved it for you Fred. May I ask that you mark my suggestion as answer so others can find the soluton too.

many thanks
Richard
Tags
GridView
Asked by
Fred
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Fred
Top achievements
Rank 1
Share this question
or