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

Null reference exception when setting the DataSource of a ChildGridViewTemplate

1 Answer 388 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ami Bar
Top achievements
Rank 1
Ami Bar asked on 04 Jul 2010, 03:16 PM
Hi,

I am using RadControls for WinForms Q3 2009 SP1

I created two UserControls each one has a RadGridView in it. i.e. AListControl and BListControl.
Each RadGridView is bounded to a DataSource which list objects of type A and B.
When I use the controls separately (as I should) it works fine.

Now I try to use the RadGridView of object B as a ChildGridViewTemplate of A.
To avoid recreating the whole grid definition I use the following in AListControl constructor:

 
public AListControl() 
   InitializeComponent(); 
 
   // Create dummy BListControl 
   BListControl bListControl = new BListControl(); 
 
   // Add the B's MasterGridViewTemplate to A as a ChildGridViewTemplates 
   this.radGridViewA.MasterGridViewTemplate.ChildGridViewTemplates.Add( 
      bListControl.radGridViewB.MasterGridViewTemplate); 
 
   // Add the relation 
   GridViewRelation relation = new GridViewRelation(this.radGridViewA.MasterGridViewTemplate); 
   relation.ChildTemplate = bListControl.radGridViewB.MasterGridViewTemplate; 
   relation.RelationName = "A2B"
   relation.ParentColumnNames.Add("Id"); 
   relation.ChildColumnNames.Add("B.AId"); 
   this.radGridViewA.Relations.Add(relation); 
    

I also added a menu item in the context menu that sets the DataSource of bListControl.radGridViewB.MasterGridViewTemplate.
When I set the DataSource the application fails with the exception "Object reference not set to an instance of an object."

This is the callstack I got:

     Telerik.WinControls.GridView.dll!Telerik.WinControls.UI.GridTraverser.IsRowVisible(Telerik.WinControls.UI.GridViewRowInfo rowInfo) + 0x32 bytes   
     Telerik.WinControls.GridView.dll!Telerik.WinControls.UI.GridTraverser.MoveForward() + 0x95 bytes   
     Telerik.WinControls.GridView.dll!Telerik.WinControls.UI.GridTableElement.UpdateScrollbars(bool resetValue) + 0x165 bytes   
     Telerik.WinControls.GridView.dll!Telerik.WinControls.UI.GridTableElement.Update_OrderChanged(Telerik.WinControls.UI.GridUINotifyAction action, Telerik.WinControls.UI.GridViewRowInfo[] rowInfos) + 0x12c bytes   
     Telerik.WinControls.GridView.dll!Telerik.WinControls.UI.GridTableElement.UpdateCore(Telerik.WinControls.UI.GridUINotifyAction action, Telerik.WinControls.UI.GridViewRowInfo[] rowInfos) + 0x74 bytes   
     Telerik.WinControls.GridView.dll!Telerik.WinControls.UI.GridViewTemplate.UpdateUI(Telerik.WinControls.UI.GridUINotifyAction action = SortingChanged, Telerik.WinControls.UI.GridViewRowInfo[] rowInfos) + 0x33f bytes   
     Telerik.WinControls.GridView.dll!Telerik.WinControls.Data.DataAccessComponent.InitializeSorting() + 0x109 bytes   
     Telerik.WinControls.GridView.dll!Telerik.WinControls.Data.DataAccessComponent.InitDataGrid() + 0x14e bytes   
     Telerik.WinControls.GridView.dll!Telerik.WinControls.Data.DataAccessComponent.Bind(object dataSource, string dataMember) + 0x32c bytes   
     Telerik.WinControls.GridView.dll!Telerik.WinControls.Data.DataAccessComponent.DataSource.set(object value) + 0x65 bytes   
>   InspectSims.exe!Inspector.AListControl.ShowBsClicked(object sender = {Telerik.WinControls.UI.RadMenuItem}, System.EventArgs e = {System.EventArgs}) Line 62 + 0x2b bytes   C#

Can you tell me if this is the correct way to do this, or if there is another way to do this ?

Regards,
Ami

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 07 Jul 2010, 12:47 PM
Hello Ami Bar,

Thank you for writing. 

This exception is a result of setting the MasterGridViewTemplate from one grid to another, which is forbidden. Each grid has its own and only one MasterGridViewTemplate (this is why its called master). Please consider the following link, you might find it helpful.

 
Best wishes,
Stefan
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
Ami Bar
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or