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

NullReferenceException in Telerik.WinControls.GridView.dll

3 Answers 413 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Piotr Kochanowski
Top achievements
Rank 1
Piotr Kochanowski asked on 15 Feb 2010, 02:25 PM

Hello,

I've got a bit of a problem with Q2 2009 GridView. I use a child GridViewTemplate, but whenever I try to expand its row (with row.IsExpanded = true) I get a NullReferenceException at Telerik.WinControls.UI.DataGroup.get_RowCount()
at Telerik.WinControls.UI.GridViewInfo.SetViewInfoToRows(DataGroup rootGroup)
at Telerik.WinControls.UI.GridViewInfo.InitializeChildViewInfo()
at Telerik.WinControls.UI.GridViewTemplate.CreateGridViewInfo(DataGroup rootGroup, GridViewDataRowInfo parentRow)
at Telerik.WinControls.UI.GridViewDataRowInfo.SetExpanded(Boolean value)
at Telerik.WinControls.UI.GridViewRowInfo.set_IsExpanded(Boolean value).

After looking closely at what's going on I noticed that DataGroup.owner is null, and DataGroup.IsDisposed == true. I think the group gets disposed in DataAccessComponent.InitDataGrid() when I set DataMember of my ChildGridViewTemplate to null and its DataSource to a DataTable that was earlier filled with data. 

After that the DataGroups never get recreated, so when I try to expand my ChildGridViewTemplate, DataGroups are still disposed (with owner set to null) and I get the exception. I also noticed that if I add new data rows to the DataTable after assigning it as DataSource than the new rows expand just fine, only the old ones throw exceptions.

So my question is, is there any way I can force the DataGrid to recreate disposed DataGroup for already existing rows ?

Regards,

Piotr Kochanowski

3 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 16 Feb 2010, 09:16 AM
Hello Piotr Kochanowski,

Thank you for contacting us. Perhaps there is a bug there, but before considering that option, are you expanding the group as explained in our online help?

Please send us the code snippet that you use or a sample application about your scenario. I am looking forward to helping you further on that.

Regards,
Nick
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Piotr Kochanowski
Top achievements
Rank 1
answered on 19 Feb 2010, 03:33 PM

Hello, thanks for replying.

It's a big application so it's hard to post an example here. I don't use groups explicitly it's something ChildView does on its own when I set RowInfo.IsExpanded = true. Luckily I managed to get around the exception by assigning MasterTemplate.DataSource again after setting ChildView.DataSource. But, unfortunately I've stumbled upon another issue.

It seems that DataTable.RowChanged event doesn't always get raised when using RadGridView with a ChildViewTemplate that has a DataTable as DataSource.

Steps to replicate the problem:

Create a RadGridView with a ChildViewTemplate and a Relation, assign DataTables as DataSources to MasterGridViewTemplate and the child template. 
Expand first row, edit text in it's child template row - RowChanged is raised
Expand second row, edit text in it's child template row - RowChanged is raised
Now go back to the first edited cell, the one in first row's child row and change it - RowChanged event isn't raised anymore.

Example code follows:

using System;  
using System.Data;  
using System.Windows.Forms;  
 
namespace RadGridRowChanged  
{  
    static class Program  
    {  
        /// <summary>  
        /// The main entry point for the application.  
        /// </summary>  
        [STAThread]  
        static void Main()  
        {  
            Application.EnableVisualStyles();  
            Application.SetCompatibleTextRenderingDefault(false);  
            Application.Run(new Form1());  
        }  
    }  
 
    class Form1 : Form  
    {  
        private System.ComponentModel.IContainer components = null;  
 
        protected override void Dispose(bool disposing)  
        {  
            if (disposing && (components != null))  
            {  
                components.Dispose();  
            }  
            base.Dispose(disposing);  
        }  
 
        private void InitializeComponent()  
        {  
            Telerik.WinControls.UI.GridViewRelation gridViewRelation1 = new Telerik.WinControls.UI.GridViewRelation();  
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));  
            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();  
            this.label1 = new System.Windows.Forms.Label();  
            this.gridViewTemplate1 = new Telerik.WinControls.UI.GridViewTemplate();  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterGridViewTemplate)).BeginInit();  
            ((System.ComponentModel.ISupportInitialize)(this.gridViewTemplate1)).BeginInit();  
            this.SuspendLayout();  
            //   
            // radGridView1  
            //   
            this.radGridView1.Location = new System.Drawing.Point(15, 25);  
            //   
            //   
            //   
            this.radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.AddRange(new Telerik.WinControls.UI.GridViewTemplate[] {  
            this.gridViewTemplate1});  
            this.radGridView1.Name = "radGridView1";  
            gridViewRelation1.ChildColumnNames = new System.Collections.Specialized.StringCollection();  
            gridViewRelation1.ChildColumnNames.Add("ParentID");  
            gridViewRelation1.ChildTemplate = this.gridViewTemplate1;  
            gridViewRelation1.ParentColumnNames = new System.Collections.Specialized.StringCollection();  
            gridViewRelation1.ParentColumnNames.Add("ID");  
            gridViewRelation1.ParentTemplate = this.radGridView1.MasterGridViewTemplate;  
            gridViewRelation1.RelationName = null;  
            this.radGridView1.Relations.Add(gridViewRelation1);  
            this.radGridView1.Size = new System.Drawing.Size(644, 415);  
            this.radGridView1.TabIndex = 0;  
            //   
            // label1  
            //   
            this.label1.AutoSize = true;  
            this.label1.Location = new System.Drawing.Point(12, 9);  
            this.label1.Name = "label1";  
            this.label1.Size = new System.Drawing.Size(35, 13);  
            this.label1.TabIndex = 1;  
            this.label1.Text = "label1";  
            //   
            // Form1  
            //   
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);  
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;  
            this.ClientSize = new System.Drawing.Size(662, 452);  
            this.Controls.Add(this.label1);  
            this.Controls.Add(this.radGridView1);  
            this.Name = "Form1";  
            this.Text = "Form1";  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterGridViewTemplate)).EndInit();  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();  
            ((System.ComponentModel.ISupportInitialize)(this.gridViewTemplate1)).EndInit();  
            this.ResumeLayout(false);  
            this.PerformLayout();  
 
        }  
 
        private Telerik.WinControls.UI.RadGridView radGridView1;  
        private System.Windows.Forms.Label label1;  
        private Telerik.WinControls.UI.GridViewTemplate gridViewTemplate1;  
        DataTable dtMaster = new DataTable();  
        DataTable dtChild = new DataTable();  
          
        public Form1()  
        {  
            InitializeComponent();  
 
            dtMaster.Columns.Add("ID");  
            dtMaster.Columns.Add("Text");  
 
            dtChild.Columns.Add("ID");  
            dtChild.Columns.Add("ParentID");  
            dtChild.Columns.Add("Text");  
 
            dtMaster.Rows.Add("1""One");  
 
            dtChild.Rows.Add("1""1""One:One");  
 
            dtMaster.Rows.Add("2""Two");  
 
            dtChild.Rows.Add("1""2""Two:One");  
 
            dtChild.RowChanged += new DataRowChangeEventHandler(dtChild_RowChanged);  
 
            this.radGridView1.MasterGridViewTemplate.DataSource = dtMaster;  
 
            this.gridViewTemplate1.DataSource = dtChild;  
        }  
 
        void dtChild_RowChanged(object sender, DataRowChangeEventArgs e)  
        {  
            this.label1.Text = DateTime.Now.ToString();  
        }  
    }  
Regards,

Piotr.

0
Nick
Telerik team
answered on 19 Feb 2010, 03:42 PM
Hello Piotr Kochanowski,

Thank you for contacting us. You are correct, that is a bug. I have updated your Telerik points for reporting this issue.

We are currently re-writing RadGridView hierarchy logic from scratch and the bug will not appear in our next release which is expected at the beginning of March. Unfortunately, I cannot provide a work-around as the behavior is internal to RadGridView.

Do not hesitate to write me back if you have further questions.

Best wishes,
Nick
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Piotr Kochanowski
Top achievements
Rank 1
Answers by
Nick
Telerik team
Piotr Kochanowski
Top achievements
Rank 1
Share this question
or