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

NullReferenceException when load gridview

4 Answers 360 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yu
Top achievements
Rank 1
Yu asked on 25 Mar 2011, 08:23 AM
Hello,

I have a usercontrol with radTabControl + radGridView (version:2011.1.322.40), the code structure like this:

<Grid>
<telerik:RadTabControl>            
<telerik:RadTabItem> <Grid /> </telerik:RadTabItem>
<telerik:RadTabItem> <telerik:RadGridView ItemsSource="{Binding items1}" /> </telerik:RadTabItem>            
<telerik:RadTabItem> <telerik:RadGridView ItemsSource="{Binding items2}" /> </telerik:RadTabItem>            
<telerik:RadTabItem> <telerik:RadGridView ItemsSource="{Binding items3}" /> </telerik:RadTabItem>            
<telerik:RadTabItem> <telerik:RadGridView ItemsSource="{Binding items4}" /> </telerik:RadTabItem>            
</
telerik:RadTabControl>
</Grid>

I use it in MainWindow, like this:

<ContentControl ContentTemplate="{StaticResource DetialsDataTemplate}" 
                Content="{Binding Path=SelectedDetails}" />

The SelectedDetails is a entity returning from EF that support lazyloading.

Start application, it's ok to show first tab. When I click other tab to show gridview, It raise below exception:

System.NullReferenceException: Object reference not set to an instance of an object.

   at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.MoveToPosition(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem, GeneratorState& state)

   at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.Generator..ctor(GridViewItemContainerGenerator factory, GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem)

   at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.StartAt(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem)

   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

   at System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Border.MeasureOverride(Size constraint)

  at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Control.MeasureOverride(Size constraint)

   at Telerik.Windows.Controls.GridView.GridViewDataControl.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Border.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Border.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Border.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Control.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.ContextLayoutManager.UpdateLayout()

   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)

   at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()

   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()

   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)

   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)

   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

I really appreciate for any help.

Yu

4 Answers, 1 is accepted

Sort by
0
Yu
Top achievements
Rank 1
answered on 27 Mar 2011, 08:45 AM
StaticResource:

<DataTemplate x:Key="DetialsDataTemplate">
    <view:DetailsView />
</DataTemplate>

DetialsView;

<Grid>
<telerik:RadTabControl>            
<telerik:RadTabItem> <Grid /> </telerik:RadTabItem>
<telerik:RadTabItem> <telerik:RadGridView ItemsSource="{Binding items1}" /> </telerik:RadTabItem>            
<telerik:RadTabItem> <telerik:RadGridView ItemsSource="{Binding items2}" /> </telerik:RadTabItem>            
<telerik:RadTabItem> <telerik:RadGridView ItemsSource="{Binding items3}" /> </telerik:RadTabItem>            
<telerik:RadTabItem> <telerik:RadGridView ItemsSource="{Binding items4}" /> </telerik:RadTabItem>            
</
telerik:RadTabControl>
</Grid>

0
Mattias
Top achievements
Rank 2
answered on 28 Mar 2011, 01:13 PM
Having the same issue, appears mainly on slower computers, so perhaps some timing issue.

2010 Q3 had similar issues(but in Telerik.Windows.Controls.GridView.GridViewCellBase.ClearCell(GridViewRowItem ownerRow, GridViewColumn gridColumn)) but these where solved in internal build 2010.3.1507.40.

So if i revert to 2010.3.1507.40 everything works but if i upgrade to the 2011 Q1 (or latest internal build) i get this exception:

System.NullReferenceException: Object reference not set to an instance of an object.

   at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.MoveToPosition(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem, GeneratorState& state)

   at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.Generator..ctor(GridViewItemContainerGenerator factory, GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem)

   at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.StartAt(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem)

   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size constraint)

0
Yordanka
Telerik team
answered on 28 Mar 2011, 04:58 PM
Hi,

We tried to reproduce this exception, but to no avail. Please, refer to the attached sample project (based on the code provided) where everything works as expected. If the sample does not help you, could you give us more details on how to reproduce the problem?
 
Greetings,
Yordanka
the Telerik team
0
Yu
Top achievements
Rank 1
answered on 30 Mar 2011, 04:01 AM
Thanks. I have solved this problem.

I have a property in entity for databinding, like this:

public partial class entity : EntityObject
{
    ...    
    public IEnumerable<subEntity> OrderedSubEntites
   
{
        return this.subEntities.OrderBy(x=>x.Name);
    }
    ...
}

It's OK on development enviroment. But it raise NullReferenceException on test enviroment that slower than development enviroment.

I changed the codes, like this:

public partial class entity : EntityObject
{    
    ...
    
private ObservableCollection<subEntity> 
_orderedSubEntities,     
    
public O
bservalbeCollection<subEntity> OrderedSubEntites   
    {
       
if (_orderedSubEntities == 
null)        
        {            
            _orderedSubEntities = new ObservableCollection<subEntity>();            
            foreach(var item in this.subEntities.OrderBy(x=>x.Name)
            {                
                _orderedSubEntities.Add(item);            
            }        
        }
       
return 
_orderedSubEntities;
    }
    ...
}

It works on both development enviroment and testing enviroment. :).

Yu
Tags
GridView
Asked by
Yu
Top achievements
Rank 1
Answers by
Yu
Top achievements
Rank 1
Mattias
Top achievements
Rank 2
Yordanka
Telerik team
Share this question
or