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

Projected Property Sort Causes Exception

4 Answers 50 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael MSTG
Top achievements
Rank 1
Michael MSTG asked on 29 Sep 2011, 03:06 PM

Something has changed in the latest version (2011.2.920.1040) of the GridView in handling programatic sorting.  Let me start with the white screen exception then explain how we add the sort descriptor:

Error: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.Windows.Data.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName, Type memberType)
   at Telerik.Windows.Data.Expressions.PropertyAccessExpressionBuilder.CreateMemberAccessExpressionOverride()
   at Telerik.Windows.Data.Expressions.MemberAccessExpressionBuilderBase.CreateMemberAccessExpression()
   at Telerik.Windows.Controls.GridViewColumn.CreateSortKeyExpression(ParameterExpression parameterExpression, ExpressionBuilderOptions options)
   at Telerik.Windows.Controls.GridView.ColumnSortDescriptor.CreateSortKeyExpression(ParameterExpression parameterExpression)
   at Telerik.Windows.Data.SortDescriptorBase.CreateSortKeyExpression(Expression itemExpression)
   at Telerik.Windows.Data.SortDescriptorExtensions.GetSortKeyLambda(ISortDescriptor sortDescriptor, Type itemType)
   at Telerik.Windows.Data.QueryableCollectionView.InitializeInternalList(IQueryable view)
   at Telerik.Windows.Data.QueryableCollectionView.CreateInternalList()
   at Telerik.Windows.Data.QueryableCollectionView.get_InternalList()
   at Telerik.Windows.Data.QueryableCollectionView.GetEnumerator()
   at Telerik.Windows.Data.DataItemCollection.GetFlatEnumerator()
   at Telerik.Windows.Data.DataItemCollection.GetEnumerator()
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.EnsureItems()
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

Our system is set up to at times override the default sorting set up a domain data source if the user so chose to.  On a first load, say we sort by a column called 'code.'  During the use of the page, the user can choose to resort the grid with a different column.  When they leave the page, during the unloaded event we then capture which sort they put into place and store it in app resources.  If they navigate back to the page, we then restore those custom sort descriptors programatically.  Here is where that issue above comes into place.

The code to restore the setting (after retreiving it from app resources) - I've set this code up with hard coded strings to explain the example after:

dds.SortDescriptors.Add(New Windows.Controls.SortDescriptor("EntityB.Description", ListSortDirection.Ascending))
 
Dim columnSort As New Telerik.Windows.Controls.GridView.ColumnSortDescriptor()
columnSort.Column = grd.Columns("EntityBDescription")
columnSort.SortDirection = ListSortDirection.Ascending
grd.SortDescriptors.Add(columnSort)

Domain data source is set up for AutoLoad to false and after the code runs above, it is programatically changed to true but after the code above has completed.

Because we are using a Domain Data Source (DDS), we found that the sort must be set up on the DDS first then the grid.  At times, however, that sort path may be different for each; specifically when trying to sort via a projected property (i.e. a property from a reference property of the entity being bound).  If Entity A has a relationship to Entity B, Entity Framework obviously sets up a property on Entity A called 'Entity B.'  Using include statements, we set up a projected property for Entity B's Description field called "EntityBDescription" which will include this property directly to Entity A for display.  The problem is the actual sort path would be "EntityB.Description" for the DDS but "EntityBDescription" for the grid.  This approach worked perfectly on the GridView until now.

On the return visit, the restore code above produces the exception that I listed and I'm unsure as to why.

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 30 Sep 2011, 06:57 AM
Hello,

 Can you post more info about DataType property value of this column?

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michael MSTG
Top achievements
Rank 1
answered on 30 Sep 2011, 02:19 PM
The columns in which we reproduced the error have all been strings.
0
Vlad
Telerik team
answered on 03 Oct 2011, 06:44 AM
Hi,

 Please open support ticket and send us small project where we can reproduce and debug the problem.

Best wishes,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
PJ Melies
Top achievements
Rank 1
answered on 28 Nov 2011, 11:08 PM
We are also getting this exact exception and call stack.  

In our case, we are using the Persistance Framework to restore a user's grid configuration (including sort descriptors) but this happens before the data is actually loaded into the grid.  I've programmatically set the DataType of the columns of the grid and that seems to have fixed the problem EXCEPT for when the sort is on a GridViewHyperlinkColumn.  I've set the DataType to typeof(string) but that doesn't work like it does for the GridViewDataColumns.

Any ideas on how to get around this problem?

ANSWER- problem is solved.  The code was setting the DataType casting the column as GridViewHyperlinkColumn but the XAML declared it as a GridViewDynamicHyperlinkColumn.
Tags
GridView
Asked by
Michael MSTG
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Michael MSTG
Top achievements
Rank 1
PJ Melies
Top achievements
Rank 1
Share this question
or