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
TestGridForm.Designer.cs
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
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