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

GridViewComboBoxColumn and SortMemberPath

2 Answers 309 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Licenses
Top achievements
Rank 1
Licenses asked on 09 Aug 2010, 09:29 AM
Hello,

I'm having trouble using the GridViewComboBoxColumn and the SortMemberPath. For some reason I always get an System.ArgumentException and there is no other information provided except the exception message that states: "Value does not fall within the expected range". So I'll explain what I'm doing and hopefully somebody notices what I'm doing wrong.

First of all the database layout:
I have a table Employee that has a column EmployeeType. This is a foreign key to a table called OptionDetails that contains all types of employees. (The types must be in a different table to be able to translate each employee type.) In fact OptionDetails also contains types of addresses, different languages, etc. So all the things you could bind to a ComboBox.

So I would like to have a grid that shows me the employee name and its type. Everything works as expected, except for the sorting and grouping. Here's the XAML:
<telerikGrid:RadGridView x:Name="empList" ItemsSource="{Binding Employees}">
   <telerikGrid:RadGridView.Columns>
      <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Name}" />
      <telerikGrid:GridViewComboBoxColumn UniqueName="empTypesCol" DataMemberBinding="{Binding EmployeeTypeOptionDetailId}" SelectedValueMemberPath="Id" DisplayMemberPath="Description" SortMemberPath="Description"  />
   </telerikGrid:RadGridView.Columns>
</telerikGrid:RadGridView>

I set the ItemsSource in code behind like this:
((GridViewComboBoxColumn)workflowDefinitionList.Columns["empListCol"]).ItemsSource = listOfEmployeeTypes;

The grid is populated OK and every column has the right value filled in.
Now the real issue: When I click on the column header for the employee type column, i get this exception. If I omit the SortMemberPath, than sorting will not throw an exception. Off course everything is sorted then on the EmployeeTypeOptionDetailId, which is not what I want.

Does anyone have any idea? I'm puzzled at the moment that something this trivial is giving me such a headache.
Thanks,
Sodi We

2 Answers, 1 is accepted

Sort by
0
Licenses
Top achievements
Rank 1
answered on 09 Aug 2010, 09:33 AM
I've taken a further look and it seems like the property for the SortMemberPath must be referring to Employee itself, and not to the ItemsSource item, OptionDetail. Because Employee does not have a property "Description" the error is thrown.

Message: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: System.ArgumentException: Invalid property or field - 'Description' for type: Employee
   bij Telerik.Windows.Data.Expressions.MemberAccessTokenExtensions.CreateMemberAccessExpression(IMemberAccessToken token, Expression instance)
   bij Telerik.Windows.Data.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName)
   bij Telerik.Windows.Data.Expressions.PropertyAccessExpressionBuilder.CreateMemberAccessExpressionOverride()
   bij Telerik.Windows.Data.Expressions.MemberAccessExpressionBuilderBase.CreateMemberAccessExpression()
   bij Telerik.Windows.Data.Expressions.MemberAccessExpressionBuilderBase.CreateLambdaExpression()
   bij Telerik.Windows.Data.SortDescriptorCollectionExpressionBuilder.Sort()
   bij Telerik.Windows.Data.QueryableCollectionView.CreateView()
   bij Telerik.Windows.Data.QueryableCollectionView.CreateInternalList()
   bij Telerik.Windows.Data.QueryableCollectionView.InternalGetItemAt(Int32 index)
   bij Telerik.Windows.Data.QueryableCollectionView.GetItemAt(Int32 index)
   bij Telerik.Windows.Data.DataItemCollection.get_Item(Int32 index)
   bij Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.Generator.GenerateNext(Boolean stopAtRealized, Boolean& isNewlyRealized)
   bij Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.GenerateNext(Boolean& isNewlyRealized)
   bij Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size constraint)
   bij System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)


This logic however seems wrong to me. Because the user will see the description of the OptionDetail (employeeType) shouldn't the SortMemberPath be a property of this OptionDetail?

Any help is appreciated,
Sodi We
0
Pavel Pavlov
Telerik team
answered on 12 Aug 2010, 12:48 PM
Hello Sodi We,

Sorting would work only over properties on the objects in the ItemsSource of RadGridView.
The lookup logic that translates id to display value happens on the UI and the data engine is not aware of it.

The suggested approach on sorting the combo column values in your case would be to implement custom sorting. This includes handling the sorting event and performing your own sorting logic inside.

All the best,
Pavel Pavlov
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
Licenses
Top achievements
Rank 1
Answers by
Licenses
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or